1Z0-829 Working with Streams and Lambda Expressions Practice Question
Exhibit
List<String> list = Arrays.asList("a", "b", "c");
Stream<String> stream = list.stream();
stream.forEach(System.out::print);
stream.forEach(System.out::print);Refer to the exhibit. What is the result?
⚠ Common exam trap
Oracle Java 17 exams often test the misconception that a stream can be reused like a collection, leading candidates to expect multiple traversals or to overlook the single-use contract enforced by the Stream API.
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
✓
IllegalStateException
The code attempts to call `findAny()` on a `Stream` that has already been consumed by a terminal operation (`forEach`). Once a terminal operation is executed on a stream, the stream is closed and cannot be reused. Any subsequent call to a terminal operation on the same stream reference throws `IllegalStateException`. Option C is correct because the second terminal operation violates the single-use contract of streams.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
abc
Why it's wrong here
Only the first forEach prints abc, but the second forEach will cause an exception.
- ✗
NullPointerException
Why it's wrong here
No null pointer issue here.
- ✓
IllegalStateException
Why this is correct
Correct. A stream cannot be reused after a terminal operation.
- ✗
abcabc
Why it's wrong here
The stream is already consumed; the second forEach will not execute.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-829 question from scratch — 513 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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.