Practice mode Java

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.