Courseiva
Working with Streams and Lambda ExpressionshardMultiple ChoiceObjective-mapped

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

Exhibit

Refer to the exhibit.
var result = Stream.of("1", "2", "3")
    .map(Integer::parseInt)
    .collect(Collectors.teeing(
        Collectors.summingInt(i -> i),
        Collectors.counting(),
        (sum, count) -> sum / count
    ));
System.out.println(result);

What is the output of the following code? ```java System.out.println(Stream.of(1, 2).map(i -> i * 2.0).count()); ```

⚠ Common exam trap

The trap here is that candidates may mistakenly think the `map` operation changes the return type of `count()` or that the output would be a floating-point number (2.0) because the mapping produces `Double` values, but `count()` always returns a `long` regardless of the stream's element 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

2

The code is: ```java System.out.println(Stream.of(1, 2).map(i -> i * 2.0).count()); ``` This creates a stream of integers 1 and 2, maps each to a Double (2.0 and 4.0), and then calls count() which returns the number of elements in the stream, which is 2. count() returns a long, but when printed, it outputs 2 (not 2.0). Option C is correct because the stream has two elements.

Answer analysis

Option-by-option breakdown

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

  • 2.0

    Why it's wrong here

    The result is an integer (2), not a double.

  • 1

    Why it's wrong here

    Incorrect calculation.

  • 2

    Why this is correct

    6/3 = 2, printed as 2.

  • Compilation error

    Why it's wrong here

    The code compiles; teeing is available since Java 12.

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 →

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.