java.util.TreeMap.lowerEntry() 方法
描述
lowerEntry(K key) 方法用于返回与严格小于给定键的最大键关联的键值映射,如果没有这样的键,则返回 null。
声明
以下是 java.util.TreeMap.lowerEntry() 方法的声明。
public Map.Entry<K,V> lowerEntry(K key)
参数
key − 这是要检查的关键。
返回值
该方法调用返回一个最大键小于键的条目,如果没有这样的键,则返回 null。
异常
ClassCastException − 如果指定的键无法与映射中当前的键进行比较,则会引发此异常。
NullPointerException − 如果指定的键为空并且此映射使用自然排序,或者其比较器不允许空键,则会引发此异常。
示例
下面的例子展示了 java.util.TreeMap.lowerEntry() 方法的使用。
package com.tutorialspoint;
import java.util.*;
public class TreeMapDemo {
public static void main(String[] args) {
// creating tree map
TreeMap<Integer, String> treemap = new TreeMap<Integer, String>();
// populating tree map
treemap.put(2, "two");
treemap.put(1, "one");
treemap.put(3, "three");
treemap.put(6, "six");
treemap.put(5, "five");
// getting lower entry
System.out.println("Checking lower entry");
System.out.println("Value is: "+ treemap.lowerEntry(5));
}
}
让我们编译并运行上面的程序,这将产生以下结果.
Checking lower entry Value is: 3=three

