What does the Java statement Stream.of(1, 2).peek(System.out::print); print?
Correct answer B. Nothing
Explanation
Intermediate operations such as peek, filter and map are lazy. They merely describe the pipeline, and no element flows until a terminal operation such as forEach or count starts it. With no terminal operation here, the action never runs and nothing is printed. Adding a terminal operation is what triggers traversal of the source.
Answer checked How we write and check questions
Discussion