What is the result of the following?
IntStream s = IntStream.empty(); System.out.print(s.average().getAsDouble());
D.
The average()
method returns an OptionalDouble.
This interface has a getAsDouble()
method rather than a get()
method, so the code does compile.
The stream is empty, so the optional is also empty.
When trying to get the value, the code throws a NoSuchElementException, making Option D correct.