This Java Example shows how to Get floorKey in Java NavigableMap object.
Get floorKey(K key) in Java NavigableMap Example
This Java Example shows how to Get floorKey in Java NavigableMap object. To get an floorKey of NavigableMap We use Map.Entry floorKey(K key) method. This method returns the greatest key less than or equal to the given key, or null if there is no such key.
Example: FloorKeyNavigableMap.java
package devmanuals.com; import java.util.*; public class FloorKeyNavigableMap { public static void main(String[] args) { NavigableMap<Integer, String> Nmap = new TreeMap<Integer, String>(); Nmap.put(2, "two"); Nmap.put(1, "one"); Nmap.put(3, "three"); Nmap.put(6, "six"); Nmap.put(5, "five"); System.out.println("The floor key of 4 is : " + Nmap.floorKey(4)); System.out.println("The floor key of 6 is : " + Nmap.floorKey(6)); } }
Output:
The floor key of 4 is : 3
The floor key of 6 is : 6 |
[ 0 ] Comments