Courseiva
Working with Streams and Lambda ExpressionshardMultiple ChoiceObjective-mapped

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

A developer writes a stream pipeline that uses flatMap and filter but notices that the intermediate streams created by flatMap are never garbage-collected early, causing memory pressure. What is the most effective optimization to reduce memory usage?

⚠ Common exam trap

Candidates often assume filter order doesn't matter because streams are lazy, but they overlook that intermediate stream objects from flatMap are not garbage-collected until the pipeline completes, making early filtering critical for memory efficiency.

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

Move the filter operation before the flatMap operation.

Moving the filter operation before flatMap reduces the number of elements passed to flatMap, thereby reducing the number of intermediate streams created and their memory footprint. Streams are lazy, so filter applied early discards unwanted elements before flatMap ever sees them, which directly lowers memory pressure from intermediate stream objects.

Answer analysis

Option-by-option breakdown

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

  • Move the filter operation before the flatMap operation.

    Why this is correct

    Filtering early reduces the number of elements fed into flatMap, thereby reducing the number of intermediate streams created.

  • Replace flatMap with map and collect into a list.

    Why it's wrong here

    This changes the semantics and does not necessarily reduce memory; it might even increase it.

  • Use a terminal operation like collect with a custom collector to process elements eagerly.

    Why it's wrong here

    This does not optimize memory; it may still hold all intermediate results.

  • Use a parallel stream to process elements concurrently.

    Why it's wrong here

    Parallelism may increase memory usage due to overhead and does not address the root cause.

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.