Created
April 1, 2017 00:24
-
-
Save liviutudor/931f373d4c443bd17b052db313c5c19f to your computer and use it in GitHub Desktop.
Find max in a list of java classes using streams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class Employee { | |
String firstName; | |
String surname; | |
double salary; //yeah, right! | |
} | |
public Optional<Employee> max(Collection<Employee> collection) { | |
return collection.stream().max((e1, e2) -> (int) Math.signum(e1.salary - e2.salary)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment