What does the following output?
Stream<Character> chars = Stream.generate(() -> 'a'); chars.filter(c -> c < 'b') .sorted() .findFirst() .ifPresent(System.out::print);
C.
The first line generates an infinite stream.
The stream pipeline has a filter that lets all these elements through.
Since sorted()
requires all the elements be available to sort, it never completes, making Option C correct.