Courseiva
Working with Streams and Lambda ExpressionsmediumMultiple ChoiceObjective-mapped

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

A company processes financial transactions. Each transaction is represented by a Transaction object with fields: amount (double), currency (String), and type (String). The requirement is to compute the total amount of all transactions of type 'SALE' in USD. The transactions are stored in a List<Transaction>. Which code correctly accomplishes this using streams?

⚠ Common exam trap

Oracle often tests the order of stream operations — specifically that filter must come before mapToDouble when the filter condition depends on object fields, otherwise the stream loses access to the original object type.

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

transactions.stream().filter(t -> t.type().equals("SALE") && t.currency().equals("USD")).mapToDouble(Transaction::amount).sum()

Ly filters transactions to only those with type 'SALE' and currency 'USD', then maps each to its amount as a double, and sums them using sum(). This satisfies the requirement exactly: total amount of 'SALE' transactions in USD.

Answer analysis

Option-by-option breakdown

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

  • transactions.stream().mapToDouble(Transaction::amount).filter(t -> t.type().equals("SALE")).sum()

    Why it's wrong here

    mapToDouble returns DoubleStream, which does not have type method; filter cannot be applied after mapToDouble in this way.

  • transactions.stream().filter(t -> t.type().equals("SALE")).filter(t -> t.currency().equals("USD")).mapToDouble(Transaction::amount).sum()

    Why it's wrong here

    Filters by type then currency, but currency filter is not needed if only SALE transactions are considered; also missing currency check for USD.

  • transactions.stream().map(Transaction::amount).reduce(0.0, (a, b) -> a + b)

    Why it's wrong here

    Missing filter for type and currency; also reduce works but sum() is more concise.

  • transactions.stream().filter(t -> t.type().equals("SALE") && t.currency().equals("USD")).mapToDouble(Transaction::amount).sum()

    Why this is correct

    Correctly filters by type and currency, then sums amounts.

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 →

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.