Java TreeSet higher() methodThe higher() is a method of TreeSet class. This method returns the smallest element in the set which is greater than the element in the argument, else it will return null if the element is not present. Syntax:Specified by:higher in interface NavigableSet<E> : It returns the smallest element in the set which is greater than the element in the argument Parameter:e - value to match Return:It returns the smallest element which is greater than e, else it returns null if there is no such element found. Throws:ClassCastException: Throws exception when typecasting is performed in the elements of Set and they are not compatible with each other. NullPointerException: Throws exception when Set elements are null. Example 1Output: TreeSet: [ 1, 2, 5, 8, 10 ] Highest value then 7 : 8 Example 2Output: TreeSet: [ D, Z, a, b ] Highest value then C : D Example 3Output: TreeSet: [ 1, 3, 6, 9, A, B, a, b ] Highest value then a : b Highest value then 3 : 6 Next TopicJava-treeset-isempty-method |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India