Courseiva
Working with Streams and Lambda ExpressionsmediumMultiple ChoiceObjective-mapped

1Z0-829 Working with Streams and Lambda Expressions Practice Question

Exhibit

List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
int sum = numbers.stream()
    .filter(n -> n % 2 == 0)
    .mapToInt(n -> n * 2)
    .sum();
System.out.println(sum);

Refer to the exhibit. What is the output?

⚠ Common exam trap

Candidates often misunderstand the identity value in reduce operations. A common mistake is to think the identity is an additional stream element, or to use the wrong identity (e.g., 0 for multiplication), which would yield 0. In this example, the identity 1 and multiplication accumulate the elements 2, 3, 2 to 12.

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

12

(12). The exhibit shows a stream reduction with identity value 1 and elements 2, 3, 2. The reduce operation multiplies each element with the accumulated result: 1 * 2 = 2, 2 * 3 = 6, 6 * 2 = 12. The identity is the starting accumulator, not a stream element.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • 30

    Why it's wrong here

    Incorrect calculation.

  • 0

    Why it's wrong here

    The filter and map are applied correctly; sum is not 0.

  • 12

    Why this is correct

    Correct. (2*2)+(4*2)=4+8=12.

  • 20

    Why it's wrong here

    This would be the sum of squares of all numbers, but not correct.

About these practice questions

One of 513 original 1Z0-829 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.