Courseiva
Working with Streams and Lambda ExpressionseasyMultiple ChoiceObjective-mapped

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

A developer wants to compute the product of all even numbers in a stream of integers. Which of the following correctly implements this using streams?

⚠ Common exam trap

The trap here is that candidates often forget the identity value must be the neutral element for the reduction operation, so they pick Option B with identity 0 for multiplication, or they skip filtering entirely and pick Option C, thinking the product of all numbers is sufficient.

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

filter(n -> n % 2 == 0).reduce(1, (a, b) -> a * b)

It first filters the stream to keep only even numbers (n % 2 == 0), then uses reduce with an identity of 1 and a multiplication lambda (a, b) -> a * b. The identity 1 is the neutral element for multiplication, ensuring that if no even numbers exist, the result is 1 rather than an error or incorrect value.

Answer analysis

Option-by-option breakdown

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

  • reduce(1, (a, b) -> (a % 2 == 0) ? a * b : a)

    Why it's wrong here

    The lambda is not a valid BinaryOperator; it conditionally multiplies, but reduce expects a function that is applied uniformly to pairs of elements. This will produce incorrect results.

  • filter(n -> n % 2 == 0).reduce(0, (a, b) -> a * b)

    Why it's wrong here

    Identity 0 causes the product to always be 0, which is incorrect.

  • reduce(1, (a, b) -> a * b)

    Why it's wrong here

    This multiplies all elements together, ignoring the even condition.

  • filter(n -> n % 2 == 0).reduce(1, (a, b) -> a * b)

    Why this is correct

    Correct. Filter ensures only even numbers are processed, then reduction multiplies them using identity 1.

Quick reference

Cloud Service Model Comparison

ModelYou ManageProvider ManagesExamples
IaaSOS, runtime, apps, dataHardware, hypervisor, networkingEC2, Azure VMs, GCP Compute Engine
PaaSApps and dataOS, runtime, middleware, hardwareElastic Beanstalk, Azure App Service
SaaSData and settings onlyEverything elseMicrosoft 365, Salesforce, Workday
FaaS / ServerlessFunction code onlyInfra, scaling, runtimeLambda, Azure Functions, Cloud Run
CaaSContainers and appsKubernetes, OS, hardwareEKS, AKS, GKE

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.