Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Finding the max in a java collection using streams
public Optional<Integer> max(Collection<Integer> collection) {
return collection.stream().max(Integer::max);
}
// usage
List<Integer> list = ...;
int m = max(list).orElse(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment