1Z0-829 Working with Streams and Lambda Expressions Practice Question
A stream pipeline uses the peek method for debugging. Which statement about peek is correct?
⚠ Common exam trap
Many exam-takers assume `peek` is a terminal operation or that it always executes for every element, confusing it with `forEach` or ignoring the Stream API's lazy evaluation and optimization guarantees.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
peek is an intermediate operation used for debugging; it is not suitable for production side effects.
The `peek` method is an intermediate operation in the Stream API, designed primarily for debugging to observe elements as they flow through the pipeline. It is not intended for production side effects because its execution is not guaranteed for every element (e.g., due to short-circuiting or optimization), and relying on it for stateful operations can lead to unpredictable behavior.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
peek is a terminal operation that prints elements.
Why it's wrong here
Peek is intermediate.
- ✗
peek can only be used with parallel streams.
Why it's wrong here
It can be used with any stream.
- ✓
peek is an intermediate operation used for debugging; it is not suitable for production side effects.
Why this is correct
Correct: Peek is intended for debugging and should not be used for production side effects because its execution is not guaranteed.
- ✗
peek is an intermediate operation, and it is guaranteed to be executed for each element.
Why it's wrong here
Not guaranteed; the Java documentation says it exists mainly for debugging and may not be executed if the pipeline is optimized.
Go deeper
Related to this question
About these practice questions
One of 513 original 1Z0-829 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.