SortedSet

SortedSet

  • It is the child interface set.
  • If we want to represent a group of objects without duplicates, according to some sorting order, then we should go for SortedSet interface.
  • The sorting order can be natural sorting order or customized sorting order.
  • SortedSet defines the following six specific methods.
  1. Object first ();
  2. Object last ();
  3. SortedSet headset (object o ) // returns sortedset, whose elements are less than the specified object.
  4. SortedSet tailset ( object o )//  returns the SortedSet, whose elements are greater than or equal to object.
  5. SortedSet subset ( object 01, object 02 ) ; //  returns the SortedSet, whose elements are greater than or equal to 01 & less than 02.
  6. Comparator comparator () // returns the Comparator object, that describes underlying sorting techniques. If we are depending on natural sorting order, then this method returns null
  • First () → 100
  • Last () → 106
  • Headset ( 103 ) → 100, 101, 102
  • Tailset ( 103 ) → 103,104,105,106
  • Subset ( 100,105 ) → 101,102,103,104
  • Comparator () → null

Leave a Reply