SortedSet Class

  • It is child interface of Set.
  • If we want to represent a group of “unique objects” where duplicates are not allowed and all objects must be inserting according to some sorting order then we should go for SortedSet interface.
  • That sorting order can be either default natural sorting (or) customized sorting order.
  • SortedSet interface define the following 6 specific methods.

1. Object first();

2. Object last();

3. SortedSet headSet(Object obj);

Returns the SortedSet whose elements are <obj.

4. SortedSet tailSet(Object obj);

It returns the SortedSet whose elements are >=obj.

5. SortedSet subset(Object o1,Object o2);

Returns the SortedSet whose elements are >=o1 but <o2.

6. Comparator comparator();

Returns the Comparator object that describes underlying sorting technique. If we are following default natural sorting order then this method returns null.

SortedSet Class

Scroll to top