- max operation on stream returns an optional of the maximum item in the stream.
- Another implementation of max operation returns an optional of the maximum item in the stream with respect to a comparator function.
int stream one to three
IntStream oneToThree = IntStream.of(1, 2, 3);
IntStream oneToTwo = IntStream.of(1, 2);
order by greater number comparator
Comparator<Integer> orderByGreaterNumber = (n1, n2) -> n1.compareTo(n2);
log.info("obtaining the max item in oneToThree stream: " + oneToThree.max());
log.info("obtaining max item in oneToTwo stream using a comparator: " + oneToTwo.boxed().max(orderByGreaterNumber));