Enrol to start learning
Reading is open to everyone. Enrolling is free, and it is what unlocks the audio lessons, practice tests and progress tracking.
15.3.2.3. TreeSet
This section
Practice test
10 questions on this section. Wrong answers show you what to read again.
Sign up to take itWhole chapter
Revision test
Mixed questions from across the chapter. Your answers get marked.
Sign up to take itQuick
Flashcard drill
2 cards from this lesson. Good the night before a test.
Try these first
- 1.
What does a TreeSet in Java guarantee about its elements?
Hint
Think about how we organize things.
- 2.
Which method would you use to add an element to a TreeSet?
Hint
Just like adding a book to a shelf.
- 3.
What is the main characteristic of TreeSet?
- It allows duplicates
- It maintains sorted order
- It uses hash table
Hint
Consider how elements are arranged.
- 4.
True or False: A TreeSet can contain null elements.
- True
- False
Hint
Think about allowing an exception.
- 5.
Create a TreeSet of your favorite movies. Ensure the movie titles are sorted alphabetically, and no duplicates are recorded. Demonstrate the functionality of adding and removing elements from the TreeSet.
Hint
Consider how you would organize movies on display.
- 6.
Implement a custom comparator that sorts a TreeSet of integers in reverse order, and demonstrate how to add elements and retrieve the smallest and largest numbers.
Hint
Think about how numbers can be arranged contrary to natural order.
Exercises
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
4 more questions available
Enrol freeQuiz
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
Get your answers marked and your progress tracked
Enrol freeChallenge Problems
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting