Java TreeSet floor() methodThe floor() method of TreeSet class is used to find an element which is less than or equal to the given element in the argument list. Syntax:Specified by:floor in interface NavigableSet<E>: In this, the NavigableSet returns the element which is less than or equal to the given element. Parameter:e - element to match Return:It returns true if the value is less than or equal to the value in the set else it returns false. 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 ] floor value of 3 in set: 2 Example 2Output: TreeSet: [ ALL, BOB, acer, bill ] Ceiling value of bi in set: acer Example 3Output: TreeSet: [1, 3, 6, 7] Ceiling value of 4 in set: 3 Ceiling value of 10 in set: 7 Next TopicJava-treeset-headset-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