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 ceiling() method in Java with Examples
- TreeSet floor() method in Java with Examples
- TreeSet descendingSet() method in Java with Examples
- TreeSet descendingIterator() method in Java with Examples
- ConcurrentSkipListSet higher() method in Java
- NavigableSet higher() method in Java
- TreeSet add() Method in Java
- TreeSet first() Method in Java
- TreeSet last() Method in Java
- TreeSet contains() Method in Java
- TreeSet hashCode() method in Java with Example
- TreeSet pollLast() method in Java with Example
- TreeSet removeAll() method in Java with Example
- TreeSet containsAll() method in Java with Example
- TreeSet comparator() 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 email@example.com. 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.