java.util.concurrent.ConcurrentSkipListMap的ceilingKey()方法是Java中的內置函數,它返回大於或等於給定鍵的最小鍵。如果沒有這樣的值,則返回null。沒有鍵時,該方法將引發NullPointerException。
用法:
public K ceilingKey(K key)
參數:該函數接受單個強製性參數key。
返回值:該函數返回大於或等於key的最小鍵;如果沒有這樣的鍵,則返回null。
異常:該方法引發兩種類型的異常:
- ClassCastException:如果指定的鍵無法與Map中當前的鍵進行比較,並且
- NullPointerException :如果指定的鍵為null。
以下示例程序旨在說明上述方法:
示例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
示例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
相關用法
- Java ConcurrentSkipListMap put()用法及代碼示例
- Java ConcurrentSkipListMap clear()用法及代碼示例
- Java ConcurrentSkipListMap remove()用法及代碼示例
- Java ConcurrentSkipListMap isEmpty()用法及代碼示例
- Java ConcurrentSkipListMap containsValue()用法及代碼示例
- Java ConcurrentSkipListMap clone()用法及代碼示例
- Java ConcurrentSkipListMap equals()用法及代碼示例
- Java ConcurrentSkipListMap size()用法及代碼示例
- Java ConcurrentSkipListMap containsKey()用法及代碼示例
- Java TreeMap ceilingKey()用法及代碼示例
- Java NavigableMap ceilingKey()用法及代碼示例
- Java TreeMap ceilingEntry()、ceilingKey()用法及代碼示例
- Java Java lang.Long.byteValue()用法及代碼示例
- Java Java lang.Long.lowestOneBit()用法及代碼示例
- Java Java lang.Long.highestOneBit()用法及代碼示例
注:本文由純淨天空篩選整理自Twinkl Bajaj大神的英文原創作品 ConcurrentSkipListMap ceilingKey() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。