Skip to content

Instantly share code, notes, and snippets.

@liviutudor
Created April 1, 2017 00:24
Show Gist options
  • Save liviutudor/931f373d4c443bd17b052db313c5c19f to your computer and use it in GitHub Desktop.
Save liviutudor/931f373d4c443bd17b052db313c5c19f to your computer and use it in GitHub Desktop.
Find max in a list of java classes using streams
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