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

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -