1Z0-829 Working with Streams and Lambda Expressions Practice Question
A stream pipeline uses sorted() with a Comparator that calls a thread-unsafe method on each element. The pipeline is parallel. What is the likely outcome?
⚠ Common exam trap
Candidates often assume `sorted()` forces sequential execution in a parallel stream, but in reality, `sorted()` is a stateful intermediate operation that still runs in parallel, and thread-safety of the comparator is the candidate's responsibility.
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
✓
The pipeline may produce incorrect ordering or throw a ConcurrentModificationException.
In a parallel stream pipeline, the `sorted()` operation requires a stable sort that merges results from multiple threads. If the provided `Comparator` calls a thread-unsafe method on each element, concurrent invocations from different threads can cause race conditions, leading to incorrect ordering or a `ConcurrentModificationException` if the method modifies shared state. The pipeline does not automatically fall back to sequential execution for `sorted()` when the comparator is stateful or unsafe.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
The pipeline may produce incorrect ordering or throw a ConcurrentModificationException.
Why this is correct
Correct: A non-thread-safe comparator can cause data corruption or exceptions due to concurrent access.
- ✗
The pipeline will throw an exception because the comparator is stateful.
Why it's wrong here
Not necessarily; it may silently produce wrong results.
- ✗
The pipeline will sort correctly because sorted() is a sequential operation.
Why it's wrong here
In parallel streams, sorted() internally uses parallel sorting algorithms that may call the comparator from multiple threads.
- ✗
The pipeline will run sequentially because the stream source is not ordered.
Why it's wrong here
Ordering does not guarantee sequential execution in parallel streams.
Go deeper
Related to this question
About these practice questions
This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.