1Z0-829 Working with Streams and Lambda Expressions Practice Question
Exhibit
Refer to the exhibit.
```java
List<Integer> source = new ArrayList<>(Arrays.asList(1, 2, 3, 4));
List<Integer> results = new ArrayList<>();
source.parallelStream()
.map(n -> { results.add(n); return n * 2; })
.forEachOrdered(System.out::println);
```Assuming the code runs in a multithreaded environment, which statement best describes the behavior?
⚠ Common exam trap
Oracle often tests the misconception that ConcurrentModificationException is the only risk when modifying a collection from multiple threads, but the actual trap here is that parallel streams with stateful lambdas cause data races leading to missing or duplicate entries, not necessarily an exception.
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
✓
It prints the doubled numbers in a non-deterministic order and results may contain missing or duplicate entries.
Using a parallel stream with a stateful lambda (e.g., modifying an external `results` list inside `peek` or `forEach`) introduces data races and non-deterministic behavior. The `peek` operation is not synchronized, so the order of printed doubled numbers is unpredictable, and concurrent modifications to the shared `results` list can cause missing or duplicate entries due to race conditions.
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 code will compile but throw an exception at runtime because of the use of parallel stream with stateful lambda.
Why it's wrong here
No runtime exception occurs directly from the stateful lambda, but data corruption may occur.
- ✗
It prints the doubled numbers in order (2, 4, 6, 8) and results contains [1,2,3,4] in that order.
Why it's wrong here
Incorrect: The map operation is performed in parallel, so results list may not maintain order and may have race conditions.
- ✗
It may produce a ConcurrentModificationException because results is modified while iterating.
Why it's wrong here
ConcurrentModificationException is not thrown because the stream does not iterate over results; it's a separate collection. However, race conditions are possible.
- ✓
It prints the doubled numbers in a non-deterministic order and results may contain missing or duplicate entries.
Why this is correct
Correct: Parallel stream processes elements concurrently, so the order of map execution is non-deterministic. The shared results list is not thread-safe, leading to data corruption.
Quick reference
Cloud Service Model Comparison
| Model | You Manage | Provider Manages | Examples |
|---|---|---|---|
| IaaS | OS, runtime, apps, data | Hardware, hypervisor, networking | EC2, Azure VMs, GCP Compute Engine |
| PaaS | Apps and data | OS, runtime, middleware, hardware | Elastic Beanstalk, Azure App Service |
| SaaS | Data and settings only | Everything else | Microsoft 365, Salesforce, Workday |
| FaaS / Serverless | Function code only | Infra, scaling, runtime | Lambda, Azure Functions, Cloud Run |
| CaaS | Containers and apps | Kubernetes, OS, hardware | EKS, AKS, GKE |
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.