1Z0-829 Working with Streams and Lambda Expressions Practice Question
Exhibit
List<Integer> numbers = List.of(1, 2, 3, 4, 5);
int sum = numbers.stream()
.reduce(0, (a, b) -> a + b);
System.out.println(sum);Refer to the exhibit. What is the output?
```java
import java.util.stream.IntStream;
public class Example {
public static void main(String[] args) {
int sum = IntStream.rangeClosed(0, 5).filter(i -> i >= 0) .sum(); System.out.println(sum);
} }
```
⚠ Common exam trap
The trap here is that candidates often miscount the number of elements produced by `rangeClosed` versus `range`, leading to off-by-one errors in the sum.
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
✓
15
The stream pipeline starts with `IntStream.rangeClosed(0, 5)` producing the integers 0, 1, 2, 3, 4, 5. The filter passes all these values, and the map is an identity function (or absent). The reduction sums them: 0+1+2+3+4+5 = 15. Therefore, the output is 15.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
0
Why it's wrong here
Incorrect; identity is used as starting value but final sum is 15.
- ✓
15
Why this is correct
Correct.
- ✗
10
Why it's wrong here
Incorrect; sum of 1 to 5 is 15.
- ✗
5
Why it's wrong here
Incorrect.
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.