About Question enthuware.ocpjp.v8.2.1738 :
Posted: Wed Oct 07, 2015 9:31 am
The explanation contains the following:
This is a valid reduction operation but it is not in java.util.stream.Stream interface. min and max methods are available in specialized Stream interfaces such an IntStream, LongStream, and DoubleStream.
The method 'max' is available in the Stream interface, only it takes a Comparator as an argument. The API says:
Optional<T> max(Comparator<? super T> comparator)
Returns the maximum element of this stream according to the provided Comparator. This is a special case of a reduction.
So I would argue that both 'reduce' and 'max' should be selected as the answer!
This is a valid reduction operation but it is not in java.util.stream.Stream interface. min and max methods are available in specialized Stream interfaces such an IntStream, LongStream, and DoubleStream.
The method 'max' is available in the Stream interface, only it takes a Comparator as an argument. The API says:
Optional<T> max(Comparator<? super T> comparator)
Returns the maximum element of this stream according to the provided Comparator. This is a special case of a reduction.
So I would argue that both 'reduce' and 'max' should be selected as the answer!