Is there a shorter way to sort by a comparable property using Java 8 streams than this pattern?
collection.stream()
.sorted((a,b) -> a.getProp().compareTo(b.getProp()))
Yes, you could use method reference for this:
collection.stream().sorted(Comparator.comparing(MyClass::getProp));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With