Chain methods in Comparator.comparing of List in Java 8 -
i have following objects
class trade{ private integer tradeid; private event eventid; private integer tradeversion; } class event{ private integer value; } - for above scenario trying write
comparator.comparing(trade::geteventid().getvalue()) - the above did not work
so went usual lambda following
somelist.sort((trade o1, trade o2) -> o1.geteventid().getvalue().compareto(o2.geteventid().getvalue()));
and worked curious know if #1 possible?
- tried
comparator.comparing(trade::geteventid).thencomparing(event::getvalue)no joy. - note both of these classes third party cannot alter them.
it's easy :
trades.sort(comparator.comparingint(x -> x.geteventid().getvalue())); also notice version comparator.comparing(trade::geteventid).thencomparing(event::getvalue) semantically mean first sorting eventid value looks not want in first place.
Comments
Post a Comment