Dynamic function calling in Java 8 Streams with Predicate Object -



Dynamic function calling in Java 8 Streams with Predicate Object -

here parent class

class parent { string attrib1; string attrib2; string attrib3; // getters , setters of 3 fields

then created list

list<parent> objlist = new arraylist<parent>();

then added number of parent objects objlist.

now want filter these objects based on value of fields in class. field name dynamically. want utilize streams purpose.

list<parent> temp = objlist.stream() .filter(nesteddo -> nesteddo.getattrib2() == "manu") .collect(collectors.tolist());

here getattrib2() varies. can getattrib1() or getattrib3().

so need dynamic function calling. can accomplish using predicates. unfortunately, don't know predicate object. please explain reply elaborately concepts within it.

yes, can create different predicate , utilize them based on condition.

predicate<parent> first= e -> e.getattrib1().equals("nanu"); predicate<parent> second= e -> e.getattrib2().equals(".."); list<parent> temp = objlist.stream() .filter(first) // can phone call sec .collect(collectors.tolist());

java java-8

Comments

Popular posts from this blog

Using Android Volley to post an array to PHP -

python - How to add an model instance to a django queryset? -

angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -