Rewrite existing code with Java 8 Lambda -
i have 1 object, 2 conditions , need convert list.
selectitem
hasgetlabel
,getvalue
- casting problem
- expect result -> list of employees
- object refer class (example: employees.class)
the code looks like:
public static final list<employees> onfilterobjectfromselectitems(final string query,final list<selectitem> selectitemlist) { final list <employees>result = new arraylist<>(); (selectitem sl : selectitemlist) { employees x = (employees) sl.getvalue(); if (x.getcode.contains(query) || x.getname.contains(query)) { result.add(x); } } return result; }
try following code.
list<employees> employeelist = selectitemlist.stream() .filter(x-> x.getcode().contains(query) || x.getname().contains(query)) .map(e->(employees)e.getvalue()) .collect(collectors.tolist());
Comments
Post a Comment