The floor() method of java.util.TreeSet<E> class is used to return the greatest element in this set less than or equal to the given element, or null if there is no such element.
public E floor(E e)
Parameters: This method takes the value e as a parameter which is to be matched.
Return Value: This method returns the greatest element less than or equal to e, or null if there is no such element
Exception: This method throws the NullPointerException if the specified element is null and this set uses natural ordering, or its comparator does not permit null elements
Below are the examples to illustrate the floor() method
TreeSet: [10, 20, 30, 40] Floor value for 25: 20
Example 2: for NullPointerException
TreeSet: [10, 20, 30, 40] Trying to get the floor value for null Exception thrown : java.lang.NullPointerException
- Java floor() method with Examples
- TreeSet higher() method in Java with Examples
- TreeSet ceiling() method in Java with Examples
- TreeSet descendingSet() method in Java with Examples
- TreeSet descendingIterator() method in Java with Examples
- ConcurrentSkipListSet floor() method in Java
- NavigableSet floor() method in Java
- StrictMath floor() Method in Java
- TreeSet last() Method in Java
- TreeSet contains() Method in Java
- TreeSet first() Method in Java
- TreeSet add() Method in Java
- TreeSet toString() method in Java with Example
- TreeSet pollFirst() method in Java
- TreeSet subSet() 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.