Java TreeSet lower() methodThe lower() is a method of TreeSet class. This method returns the largest element in the set which is smaller than the element in argument, else it will return null if the element is not present. Syntax:Specified by:lower in interface NavigableSet<E> : It returns the largest element in the set which is smaller than the element in the argument. Parameter:e - value to match Return:It returns the largest element which is smaller 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 ] Lowest value then 7 : 5 Example 2Output: TreeSet: [ D, Z, a, b ] Lowest value then a: Z Example 3Output: TreeSet: [ 1, 3, 6, 9, A, B, a, b ] Lowest value then b : a Lowest value then 9 : 6 Next TopicJava-treeset-pollfirst-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