The higher(E ele) method of TreeSet class in Java is used to return the least element in this set which is strictly greater than the given element ele. If no such element is there then this method returns NULL.
Here, E is the type of element maintained by this TreeSet collection.
public E higher(E ele)
Parameters:It takes only one parameter ele. It is the element based on which the least value in the set which is strictly greater than this value is determined.
Return Value: It returns a value of type which this TreeSet stores which is either null or the required value.
- ClassCastException: This method throws a ClassCastException if the specified element cannot be compared with the elements of the set.
- NullPointerException: This method throws a NullPointerException if the given element is null and the set uses natural ordering or the comparator does not permit null values.
Below programs illustrate the above method:
Program 3: Program to demonstrate the NullPointerException.
Program 4: Demonstrate the ClassCastException.
java.lang.ClassCastException: java.util.LinkedList cannot be cast to java.lang.Comparable
- TreeSet descendingIterator() method in Java with Examples
- TreeSet descendingSet() method in Java with Examples
- TreeSet floor() method in Java with Examples
- TreeSet ceiling() method in Java with Examples
- ConcurrentSkipListSet higher() method in Java
- NavigableSet higher() method in Java
- TreeSet first() Method in Java
- TreeSet contains() Method in Java
- TreeSet last() Method in Java
- TreeSet add() Method in Java
- TreeSet lower() method in Java
- TreeSet iterator() Method in Java
- TreeSet remove() Method in Java
- TreeSet pollFirst() method in Java
- TreeSet headSet() Method in Java
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.