1Z0-829 Working with Arrays and Collections Practice Question
Given: TreeSet<Integer> ts = new TreeSet<>(Comparator.reverseOrder()); ts.add(10); ts.add(5); ts.add(20); ts.add(15); System.out.println(ts.first()); What is the result?
⚠ Common exam trap
Watch out — candidates often assume `first()` returns the first element added or the largest element in a reversed set, rather than understanding it always returns the smallest element according to the set's comparator.
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
✓
5
`TreeSet` with `Comparator.reverseOrder()` sorts elements in descending order (20, 15, 10, 5). The `first()` method returns the smallest element according to the comparator, which in descending order is the last element in the natural order, i.e., 5.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
20
Why it's wrong here
This is the last element, not first.
- ✗
15
Why it's wrong here
Not the first element.
- ✓
5
Why this is correct
Correct; first() returns the least element in reversed order.
- ✗
10
Why it's wrong here
Not the first element.
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.