Rewrite existing code with Java 8 Lambda -


i have 1 object, 2 conditions , need convert list.

  • selectitem has getlabel , 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

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -