The higher() method of
NavigableSet interface in Java is used to return the least element in this set strictly greater than the given element, or null if there is no such element exists.
Syntax:
E higher(E ele)
Where, E is the type of elements maintained by this Set container.
Parameters: This function accepts a parameter
ele which refers to type of element maintained by this Set container.
Return Value: It returns the least element in this set strictly greater than the given element, or null if there is no such element exists.
Below programs illustrate the higher() method in Java:
Program 1: NavigableSet with integer elements.
Output:
Least element strictly greater than 4 is: 5
Program 2: NavigableSet with string elements.