Java TreeSet class implements the Set interface that uses a tree for storage. It inherits the AbstractSet class and implements the NavigableSet interface.

Some of the features of TreeSet are:

  1. TreeSet does not allow duplicate elements.
  2. TreeSet class doesn’t allow null elements.
  3. Since elements are stored in a tree, the access and retrieval times are quite fast in a TreeSet.
  4. The elements are stored in ascending order in a TreeSet.

Get hands-on with 1200+ tech skills courses.