TreeMap floorEntry() Method in Java With Examples
The java.util.TreeMap.floorEntry() method is used to return a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key.
Parameters: This method takes one parameter key to be matched while mapping.
Return Value: This method returns an entry with the greatest key less than or equal to key, or null if there is no such key.
- ClassCastException : This exception is thrown if the specified key cannot be compared with the keys currently in the map.
- NullPointerException : This exception is thrown if the specified key is null and this map uses natural ordering, or its comparator does not permit null keys.
Example 1: When there is a key
The greatest key-value less than 18 is : 13=Thirteen
Example 2: When there is no such key
The greatest key-value less than 5 is : null