Java: Get a key-value mapping associated with the least key greater than or equal to the given key
25. Get Mapping with Ceiling Key
Write a Java program to get a key-value mapping associated with the least key greater than or equal to the given key. Return null if there is no such key.
Sample Solution:-
Java Code:
Sample Output:
Orginal TreeMap content: {10=Red, 20=Green, 30=Black, 40=White, 50=Pink } Keys greater than or equal to 20: 20=Green Keys greater than or equal to 40: 40=White Keys greater than or equal to 50: 50=Pink
For more Practice: Solve these Related Problems:
- Write a Java program to use ceilingEntry() on a TreeMap to retrieve the mapping with the least key greater than or equal to a specified key.
- Write a Java program to implement a lambda expression that returns the entry for the least key ≥ a given value using ceilingEntry().
- Write a Java program to handle null returns from ceilingEntry() by providing a default mapping.
- Write a Java program to compare the output of ceilingEntry() with a manual search through the TreeMap’s key set.
Go to:
PREV : Get TailMap from Exclusive Key.
NEXT : Get Ceiling Key in TreeMap.
Java Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.