NavigableMap floorEntry() method in Java
The floorEntry() method of NavigableMap interface in Java 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.
Syntax:
Map.Entry<K, V> floorEntry(K key)
Where, key is the key maintained by this map.
Parameters: key – the key
Return Value: It returns an entry with the greatest key less than or equal to key, or null if there is no such key.
Below programs illustrate the floorEntry() method in Java:
Program 1: When the key is integer.
// Java code to demonstrate the working of // floorEntry() method import java.io.*; import java.util.*; public class GFG { public static void main(String[] args) { // Declaring the NavigableMap of Integer and String NavigableMap<Integer, String> nmmp = new TreeMap<>(); // assigning the values in the NavigableMap // using put() nmmp.put(2, "two"); nmmp.put(7, "seven"); nmmp.put(3, "three"); System.out.println("The mapping with greatest key is : " + nmmp.floorEntry(2)); } } |
The mapping with greatest key is : 2=two
Program 2: When the key is string.
// Java code to demonstrate the working of // floorEntry() method import java.io.*; import java.util.*; public class GFG { public static void main(String[] args) { // Declaring the NavigableMap of Integer and String NavigableMap<String, String> tmmp = new TreeMap<>(); // assigning the values in the NavigableMap // using put() tmmp.put("one", "two"); tmmp.put("six", "seven"); tmmp.put("two", "three"); System.out.println("The mapping associated with greatest key is : " + tmmp.floorEntry("one")); } } |
The mapping associated with greatest key is : one=two
Reference: https://docs.oracle.com/javase/10/docs/api/java/util/NavigableMap.html#floorEntry(K)
Recommended Posts:
- NavigableMap put() Method in Java
- NavigableMap lowerEntry() method in Java
- NavigableMap size() Method in Java
- NavigableMap pollFirstEntry() method in Java
- NavigableMap ceilingKey() method in Java
- NavigableMap lastEntry() method in Java
- NavigableMap ceilingEntry() method in Java
- NavigableMap firstEntry() method in Java
- NavigableMap pollLastEntry() method in Java
- NavigableMap isEmpty() Method in Java
- NavigableMap clear() Method in Java
- NavigableMap higherEntry() method in Java
- NavigableMap higherKey() Method in Java
- NavigableMap lowerKey() Method in Java
- NavigableMap floorKey() 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 contribute@geeksforgeeks.org. 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.



