SortedSet Interface

SortedSet was introduced in java 1.2 version

Features of SortedSet : (When to use SortedSet)

  • SortedSet is a child Interface of Set Interface
  • If you want to represent a group of individual objects as a single entity where duplicates are not allowed but all objects should be inserted according to some sorted order then we should use SortedSet

Methods :

  • Object first()
  • Object last()
  • SortedSet headSet(Object o)
  • SortedSet tailSet(Object o)
  • SortedSet subSet(Object o1, Object o2)
  • Comparator comparator()
    • It is going to show the internal sorting technique
    • If it is using default sorting order then it returns null
      • Default natural sorting order of number is Ascending
      • Default natural sorting order of String is Alphabetic

Leave a Comment