The ceilingKey() method of java.util.concurrent.ConcurrentSkipListMap is an in-built function in Java which returns the least key greater than or equal to the given key. If there is no such value then null is returned. The method throws NullPointerException when there is no key.
Syntax:
public K ceilingKey(K key)
Parameter: The function accepts a single mandatory parameter key which specifies the key.
Return Value: The function returns the least key greater than or equal to key, or null if there is no such key.
Exceptions: The method throws two types of exceptions:
- ClassCastException: if the specified key cannot be compared with the keys currently in the map and
- NullPointerException: if the specified key is null.
Below programs illustrate the above above method:
Program 1:
// Java program to demonstrate // ceilingkey method in java import java.util.concurrent.ConcurrentSkipListMap; class GFG { public static void main(String[] args) { // Initializing the set // using ConcurrentSkipListMap() ConcurrentSkipListMap<Integer, Integer> mpp = new ConcurrentSkipListMap<Integer, Integer>(); // Adding elements to this set mpp.put(1, 1); mpp.put(5, 2); mpp.put(2, 7); // Printing the ConcurrentSkipListMap // Always in ascending order System.out.println("Map: " + mpp); System.out.println("key greater than or equal 3: " + mpp.ceilingKey(3)); System.out.println("key greater than or equal 2: " + mpp.ceilingKey(2)); } } |
Map: {1=1, 2=7, 5=2}
key greater than or equal 3: 5
key greater than or equal 2: 2
Program 2:
// Java program to demonstrate // ceilingkey method in java import java.util.concurrent.ConcurrentSkipListMap; class GFG { public static void main(String[] args) { // Initializing the set // using ConcurrentSkipListMap() ConcurrentSkipListMap<Integer, Integer> mpp = new ConcurrentSkipListMap<Integer, Integer>(); // Adding elements to this set mpp.put(11, 1); mpp.put(51, 42); mpp.put(92, 7); // Printing the ConcurrentSkipListMap // Always in ascending order System.out.println("Map: " + mpp); System.out.println("key greater than or equal 11: " + mpp.ceilingKey(11)); System.out.println("key greater than or equal 51: " + mpp.ceilingKey(51)); } } |
Map: {11=1, 51=42, 92=7}
key greater than or equal 11: 11
key greater than or equal 51: 51
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- ConcurrentSkipListMap put() method in Java with Examples
- ConcurrentSkipListMap size() method in Java with Examples
- ConcurrentSkipListMap containsKey() method in Java with Examples
- ConcurrentSkipListMap clone() method in Java with Examples
- ConcurrentSkipListMap remove() method in Java with Examples
- ConcurrentSkipListMap equals() method in Java with Examples
- ConcurrentSkipListMap clear() method in Java with Examples
- ConcurrentSkipListMap isEmpty() method in Java with Examples
- ConcurrentSkipListMap containsValue() method in Java with Examples
- TreeMap ceilingKey() in Java with Examples
- NavigableMap ceilingKey() method in Java
- TreeMap ceilingEntry() and ceilingKey() methods in Java
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java lang.Long.builtcount() method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
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.

