1Z0-829 Working with Arrays and Collections Practice Question
A developer needs to sort a List of Employee objects by salary (double) in descending order. Which approach is correct and efficient?
⚠ Common exam trap
Watch out — candidates often choose the stream-based approach (Option B) thinking it is more modern or functional, but the exam tests understanding that `Collections.sort()` with a custom comparator is the correct and efficient way to sort a mutable list in-place, while streams create a new collection and are less efficient for this specific requirement.
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
✓
Collections.sort(list, (e1, e2) -> Double.compare(e2.getSalary(), e1.getSalary()));
It uses `Collections.sort()` with a custom `Comparator` that performs an in-place sort of the original list, which is both efficient (no new list created) and correctly orders by salary descending via `Double.compare(e2.getSalary(), e1.getSalary())`. This avoids the overhead of stream pipeline creation and collection, and directly mutates the list as required.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Collections.sort(list, Collections.reverseOrder());
Why it's wrong here
reverseOrder requires Comparable, not custom comparator.
- ✗
list.stream().sorted((e1, e2) -> Double.compare(e2.getSalary(), e1.getSalary())).collect(Collectors.toList());
Why it's wrong here
Creates new list, does not modify original.
- ✓
Collections.sort(list, (e1, e2) -> Double.compare(e2.getSalary(), e1.getSalary()));
Why this is correct
Uses Comparator with descending order via Double.compare.
- ✗
Collections.sort(list);
Why it's wrong here
Requires Employee to implement Comparable, not specified.
Go deeper
Related to this question
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 →
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.