floorKey and ceilingKey include an exact match, while lowerKey and higherKey always skip the key given and move strictly past it.
NavigableMap<Integer, String> map = new TreeMap<>();
map.put(10, "a");
map.put(20, "b");
map.put(30, "c");
System.out.println("floorKey(20): " + map.floorKey(20));
System.out.println("lowerKey(20): " + map.lowerKey(20));
System.out.println("ceilingKey(20): " + map.ceilingKey(20));
System.out.println("higherKey(20): " + map.higherKey(20));
floorKey(20): 20
lowerKey(20): 10
ceilingKey(20): 20
higherKey(20): 30
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27