Skip to content

Instantly share code, notes, and snippets.

@liviutudor
Created April 1, 2017 00:11
Show Gist options
  • Save liviutudor/1ae30b81c6f800fec2ca358e17ad04c0 to your computer and use it in GitHub Desktop.
Save liviutudor/1ae30b81c6f800fec2ca358e17ad04c0 to your computer and use it in GitHub Desktop.
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