In TreeSet the elements are ordered using their natural
ordering, or by a Comparator provided at set creation
time, depending on which constructor is used.
Objects that implement Comparable interface can be used as the element in TreeSet.Use the following constructors for it.
- public TreeSet()
- public TreeSet(Collection<? extends E> c)
- public TreeSet(SortedSet<E> s)
The Comparable interface imposes a total ordering on the objects of each class that
implements it. This ordering is referred to as the class's natural
ordering, and the class's compareTo method is referred to as
its natural comparison method.
- public TreeSet(Comparator<? super E> comparator)