Question 232 of 513
1Z0-829 Working with Streams and Lambda Expressions Practice Question
A developer is refactoring a legacy codebase to use streams. The original code iterates over a list of 'Order' objects, filters orders with status 'PENDING', sorts them by date, and collects the order IDs into a set. Which stream pipeline correctly replaces this logic?
⚠ Common exam trap
The exam often tests the order of stream operations, specifically that sorting must occur before mapping when the sort key is a property of the original object, and that filtering early improves 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
✓
orders.stream().filter(o->o.getStatus().equals("PENDING")).sorted(Comparator.comparing(Order::getDate)).map(Order::getId).collect(Collectors.toSet())
It first filters orders with status 'PENDING', then sorts them by date using a Comparator, then maps each Order to its ID, and finally collects the IDs into a Set. This preserves the original logic: filter before sorting (to reduce the number of elements to sort), and map after sorting (since sorting requires Order objects, not IDs). Collecting into a Set automatically deduplicates IDs, matching the original intent.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
orders.stream().filter(o->o.getStatus().equals("PENDING")).sorted(Comparator.comparing(Order::getDate)).collect(Collectors.toSet())
Why it's wrong here
Collects Order objects into a Set, not the IDs. The original logic collects order IDs, so this is incorrect.
- ✗
orders.stream().filter(o->o.getStatus().equals("PENDING")).map(Order::getId).sorted().collect(Collectors.toSet())
Why it's wrong here
Sorts after mapping to IDs, sorting the IDs by natural order, not by order date. The original logic sorts by date, so this is incorrect.
- ✗
orders.stream().sorted(Comparator.comparing(Order::getDate)).filter(o->o.getStatus().equals("PENDING")).map(Order::getId).collect(Collectors.toSet())
Why it's wrong here
Sorts before filtering, which may be less efficient and does not match the original logic that filters first then sorts. Also, it sorts all orders, which is unnecessary.
- ✓
orders.stream().filter(o->o.getStatus().equals("PENDING")).sorted(Comparator.comparing(Order::getDate)).map(Order::getId).collect(Collectors.toSet())
Why this is correct
Ly filters by status 'PENDING', sorts by date using a Comparator, maps to order IDs, and collects into a Set, matching the original logic.
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 →
Last reviewed: Jul 4, 2026
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.
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.
Sign in to join the discussion.