Java Data StructuresLesson 67Free preview
Java TreeSet
This lesson is part of Java · All levels
Summary
TreeSet stores unique elements in the structure of a balanced binary search tree so that the elements are always in order. It also provides navigation such as first(), last(), ceiling(), and floor() that are useful for finding data boundaries. The elements must implement the Comparable or provide the Comparator when creating the set.
Key points
- The elements are always ordered according to a given natural ordering or comparator
- Add, remove, and contains running O(log n)
- The following is the list of the countries of the European Union.
- Do not allow the null element in normal use
- Can be reversed with new TreeSet
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.