The tailSet() method of SortedSet interface in Java is used to return a view of the portion of this set whose elements are greater than or equal to the parameter fromElement.
- The set returned by this method is backed by this set, so changes in the returned set are reflected in this set, and vice-versa.
- The set returned by this method supports all optional set operations that this set supports.
Note: The set returned by this method will throw an IllegalArgumentException if an attempt is made to insert an element outside its range.
SortedSet tailSet(E fromElement)
Where, E is the type of element maintained by this Set.
Parameters: This function accepts a single parameter fromElement which represent the low endpoint (inclusive) of the returned set.
Return Value: It returns the elements which are greater than or equal to the given argument fromElement.
- ClassCastException : It throws a ClassCastException if fromElement is not compatible with this set’s comparator (or, if the set has no comparator, if fromElement does not implement Comparable).
- NullPointerException : It throws a NullPointerException if the parameter fromElement is null.
- IllegalArgumentException : It throws an IllegalArgumentException this set itself has a restricted range, and the parameter fromElement lies outside the bounds of the range.
Below programs illustrate the above method:
Elements greater than or equal to 5 in set are : [5, 9]
Element greater than or equal to G in set is : [Geeks, It]
- TreeSet tailSet() Method in Java
- ConcurrentSkipListSet tailSet() method in Java with Examples
- SortedSet last() method in Java
- SortedSet first() method in Java
- SortedSet headSet() method in Java
- SortedSet subSet() method in Java
- SortedSet Interface in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.builtcount() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.