Created
April 1, 2017 00:11
-
-
Save liviutudor/1ae30b81c6f800fec2ca358e17ad04c0 to your computer and use it in GitHub Desktop.
Finding the max in a java collection 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
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