1Z0-829 Working with Arrays and Collections Practice Question
Which TWO are true about HashSet and TreeSet?
⚠ Common exam trap
Test-takers frequently confuse the performance guarantees of HashSet (constant-time average) with TreeSet (logarithmic time), or mistakenly think both maintain insertion order, when in fact only LinkedHashSet does.
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
✓
HashSet uses equals() and hashCode() for uniqueness, TreeSet uses compareTo() or Comparator.
HashSet relies on the equals() and hashCode() methods to determine element uniqueness, while TreeSet uses the natural ordering (compareTo()) or a provided Comparator to maintain sorted order and check for duplicates. This distinction is fundamental to how these Set implementations enforce uniqueness.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
HashSet maintains elements in insertion order.
Why it's wrong here
LinkedHashSet does.
- ✓
HashSet uses equals() and hashCode() for uniqueness, TreeSet uses compareTo() or Comparator.
Why this is correct
Correct.
- ✗
Both implement the List interface.
Why it's wrong here
They implement Set.
- ✗
Both guarantee constant-time performance for basic operations (add, remove, contains).
Why it's wrong here
TreeSet is O(log n).
- ✓
TreeSet requires elements to be mutually comparable, unless a Comparator is provided.
Why this is correct
Otherwise ClassCastException.
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.