Java SE 11 Developer (1Z0-819) — Question 44

Why would you choose to use a peek operation instead of a forEach operation on a Stream?

Answer options

Correct answer: C

Explanation

The correct answer is C because the peek operation allows you to process each element of the stream while still returning the original stream for further operations. In contrast, forEach performs an action on each element without returning a stream, and options A, B, and D do not accurately describe the functionality of peek.