Question 323 of 519
Working with Streams and Lambda ExpressionshardMultiple ChoiceObjective-mapped

IntStream Average Computation — OptionalDouble Handling

This 1Z0-829 practice question tests your understanding of working with streams and lambda expressions. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. A key principle to apply: intStream.average(). Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

Exhibit

List<Student> students = Arrays.asList(
    new Student("Alice", 85),
    new Student("Bob", 92),
    new Student("Charlie", 78),
    new Student("David", 88)
);

OptionalDouble avg = students.stream()
    .filter(s -> s.getScore() > 80)
    .mapToInt(Student::getScore)
    .average();

System.out.println(avg.orElse(0.0));

Refer to the exhibit. What is the output?

Exhibit

List<Student> students = Arrays.asList(
    new Student("Alice", 85),
    new Student("Bob", 92),
    new Student("Charlie", 78),
    new Student("David", 88)
);

OptionalDouble avg = students.stream()
    .filter(s -> s.getScore() > 80)
    .mapToInt(Student::getScore)
    .average();

System.out.println(avg.orElse(0.0));

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

88.33333333333333

The code creates an IntStream with values 85, 92, and 88, then calls average() to compute the arithmetic mean. This returns an OptionalDouble, and orElse(0.0) extracts the value. The sum 85+92+88 = 265, divided by 3 gives 88.33333333333333, which matches option B exactly. No integer division occurs because average() always returns a double.

Key principle: IntStream.average()

Answer analysis

Option-by-option breakdown

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

  • 88.0

    Why it's wrong here

    This result would occur if integer division were used (265/3 = 88), but average() always returns a double.

  • 88.33333333333333

    Why this is correct

    Correct. The average of 85, 92, and 88 is (85+92+88)/3 = 265/3 = 88.33333333333333.

    Related concept

    IntStream.average()

  • 85.0

    Why it's wrong here

    85.0 might be the minimum or median, but not the average. The sum is 265, so the average is 88.33...

  • 85.75

    Why it's wrong here

    85.75 is not the average; it might result from a miscalculation like (85+92+88)/3 = 88.33, not 85.75.

Common exam traps

Common exam trap: answer the scenario, not the keyword

The trap here is that candidates might mistakenly think integer division applies (e.g., 265/3 = 88 with truncation) or misread the output format, but the stream's `average()` method always returns a `double` with full precision.

Detailed technical explanation

How to think about this question

Under the hood, `IntStream.average()` internally uses a `DoubleSummaryStatistics` collector that accumulates the sum as a `long` and count as a `long`, then divides the sum by the count as a `double` to preserve fractional precision. This avoids integer truncation, which is a common pitfall when manually averaging integers. In real-world scenarios, such as calculating average response times from log data, using `average()` ensures accurate floating-point results without accidental integer division.

KKey Concepts to Remember

  • IntStream.average()
  • OptionalDouble.orElse()
  • Stream pipeline

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

IntStream.average()

Real-world example

How this comes up in practice

A practitioner preparing for the 1Z0-829 exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. IntStream.average() Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.

What to study next

Got this wrong? Here's your next step.

Review intStream.average(), then practise related 1Z0-829 questions on the same topic to reinforce the concept.

Related practice questions

Related 1Z0-829 practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free 1Z0-829 practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this 1Z0-829 question test?

Working with Streams and Lambda Expressions — This question tests Working with Streams and Lambda Expressions — IntStream.average().

What is the correct answer to this question?

The correct answer is: 88.33333333333333 — The code creates an IntStream with values 85, 92, and 88, then calls average() to compute the arithmetic mean. This returns an OptionalDouble, and orElse(0.0) extracts the value. The sum 85+92+88 = 265, divided by 3 gives 88.33333333333333, which matches option B exactly. No integer division occurs because average() always returns a double.

What should I do if I get this 1Z0-829 question wrong?

Review intStream.average(), then practise related 1Z0-829 questions on the same topic to reinforce the concept.

What is the key concept behind this question?

IntStream.average()

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Keep practising

More 1Z0-829 practice questions

Last reviewed: Jul 4, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.