1Z0-829 Working with Arrays and Collections Practice Question
A TreeSet<String> is used to store a list of employee names. The set currently contains "Alice", "Bob", "Charlie". What is the output after calling set.add("Bob")?
⚠ Common exam trap
Candidates often confuse the return value of add() with the behavior of a List, expecting an exception or a successful insertion, but the Set interface mandates that duplicates are silently rejected by returning false.
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
✓
false
A TreeSet implements the Set interface, which does not allow duplicate elements. When calling add("Bob") on a TreeSet that already contains "Bob", the add method returns false, indicating that the element was not added, and the set remains unchanged.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Exception
Why it's wrong here
Adding a duplicate does not throw an exception; it simply returns false.
- ✓
false
Why this is correct
TreeSet implements Set, which does not allow duplicates; add returns false.
- ✗
The set becomes ["Alice","Bob","Bob","Charlie"]
Why it's wrong here
Sets cannot contain duplicate elements.
- ✗
true
Why it's wrong here
false is returned because "Bob" already exists.
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.