java - How to use stream to filter a collection in a range -


i have domain person

public class person{   string name; } 

i have list string of person names,

listrange = new listwith("bob","john","mark"); 

and how can use java 8 stream filter in resultlist, person has name in range list. might like

resultlist.stream().filter(p->p.getname().equals(listrange.any).collect(); 

how can use lambda filter resultlist?

what looking contains method:

resultlist.stream().filter(p -> listrange.contains(p.getname()))                    .collect(collectors.tolist()); 

if name list used filter out persons result, should consider using set contains method o(1) (constant-time) result in better performance.


Comments