Which fills in the blank so the code is guaranteed to print 1?
Stream<Integer> stream = Stream.of(1, 2, 3); System.out.println(stream.___);
findAny()
first()
min()
D.
Option A is incorrect because the findAny()
might not return 1.
The result could be any of the three numbers.
Option B is incorrect because there is no first()
method available as a terminal operation.
Option C is tempting because there is a min()
method.
However, since we are working with a Stream, this method requires a Comparator as a parameter.
Therefore, Option D is the answer.