java ceilingentry_java.util.TreeMap.ceilingKey()
描述
所述ceilingKey(K key)方法用來返回的最小鍵大于或等于給定鍵,則返回null如果不存在這樣的密鑰。
聲明
以下是java.util.TreeMap.ceilingKey()方法的聲明。
public K ceilingKey(K key)
參數
key - 這是匹配的關鍵。
返回值
方法調用返回大于或等于key的最小鍵,如果沒有這樣的鍵則返回null。
異常
ClassCastException - 如果無法將指定的鍵與當前映射中的鍵進行比較,則拋出異常。
NullPointerException - 如果指定的鍵為null并且此映射使用自然排序,或者其比較器不允許空鍵,則拋出異常。
實例
以下示例顯示了java.util.TreeMap.ceilingKey()方法的用法。
package com.tutorialspoint;
import java.util.*;
public class TreeMapDemo {
public static void main(String[] args) {
// creating tree map
NavigableMap treemap = new TreeMap();
// populating tree map
treemap.put(2, "two");
treemap.put(1, "one");
treemap.put(3, "three");
treemap.put(6, "six");
treemap.put(5, "five");
System.out.println("Ceiling key entry for 4: "+ treemap.ceilingKey(4));
System.out.println("Ceiling key entry for 5: "+ treemap.ceilingKey(5));
System.out.println("Ceiling key entry for 7: "+ treemap.ceilingKey(7));
}
}
讓我們編譯并運行上面的程序,這將產生以下結果。
Ceiling key entry for 4: 5
Ceiling key entry for 5: 5
Ceiling key entry for 7: null
總結
以上是生活随笔為你收集整理的java ceilingentry_java.util.TreeMap.ceilingKey()的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: drawrect java_对于draw
- 下一篇: java 中如何实现多进程_在Java中