1Z0-829 Working with Streams and Lambda Expressions Practice Question
Given a list of integers, a developer wants to compute the sum of squares of numbers greater than 10. The following code is written:
int sum = list.stream().filter(i -> i>10).mapToInt(i->i*i).sum();
But the sum is incorrect. What is the most likely reason?
⚠ Common exam trap
Oracle often tests the misconception that `sum()` returns an `OptionalInt` (like `reduce` does) or that the order of `filter` and `mapToInt` is reversed, but the real trap is the silent NullPointerException from unboxing nulls in a lambda.
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 list might contain nulls causing NullPointerException.
If the list contains null elements, the lambda expression `i -> i > 10` will attempt to unbox a null `Integer` to an `int`, causing a `NullPointerException` at runtime. The stream pipeline itself is syntactically valid, but the presence of nulls in the source list is a common pitfall when using primitive-specialized operations like `mapToInt` after a filter that does not guard against nulls.
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 mapToInt operation is not allowed after filter.
Why it's wrong here
filter returns a Stream<Integer> which can be mapped to an IntStream via mapToInt.
- ✗
The stream is not sorted.
Why it's wrong here
Sorting is irrelevant to the computation.
- ✓
The list might contain nulls causing NullPointerException.
Why this is correct
If any element is null, unboxing in i > 10 throws NPE, making the result incorrect if caught or halting execution.
- ✗
The filter should be before mapToInt, but it is after.
Why it's wrong here
The filter is before mapToInt; that's correct.
- ✗
The sum() method returns an OptionalInt and must be orElse(0).
Why it's wrong here
IntStream.sum() returns int, not OptionalInt.
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.