Java Design Pattern
Introduction to Java 10
Introduction to Java 11
Introduction to Java 12

JAVA SortedSet

  • • It is the child interface of set.
  • • If we want to represent a group of individual object according to some sorting order and duplicates are not allow then we should go for SortedSet.

Methods specified in SortedSet

Basically, there are 6 methods available in SortedSet which are as follows:

  1. first(): it retrieves the first object from a given set of objects.
    For example,


    First (); //100

  2. last (); //107
    retrieves the last object;
  3. headset(Object o)
    retrieves one or more than one objects which are less than the specified object.

    headset(107) //[100,102,103,104,105]

  4. tailset(Object o)
    Retrieves one more than one objects which are greater than or equal to specified objects.

    tailset(103); //[103,104,105,107]

  5. subset(Object o1,objecto2)
    Retrieves one or more than one objects which are greater than or equal to Object o1 but less than Objecto2.
  6. comparator() :
    returns comparator objects which describe underlying sorting technique.

About the Author

Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc