java - Find items with matching string from a List -
i have java class:
class globalusers { string name = "" string id = "" ................ ................ } now in function:
list<globalusers> guobjs = new list<globalusers>(); here have few hundreds of objects of globalusers in list.
i want find objects of globalusers string name == "user_custom"
so result list:
list<globalusers> guobjs = *name == "user_custom"* how can easiest way?
use streams api:
guobjs.stream().filter(u -> "user_custom".equals(u.name)).collect(collectors.tolist()); filter wanted, gets function check if input value ok or not (in case if name matches requested "user_custom" value. collect takes matching results , places them in list.
Comments
Post a Comment