java.util.TreeMap.firstEntry() 方法
描述
firstEntry() 方法用于返回与此映射中的最小键关联的键值映射,如果映射为空,则返回 null。
声明
以下是 java.util.TreeMap.firstEntry() 方法的声明。
public Map.Entry<K,V> firstEntry()
参数
NA
返回值
该方法调用返回具有最少键的条目,如果此映射为空,则返回 null。
异常
NA
示例
下面的例子展示了 java.util.TreeMap.firstEntry() 方法的使用。
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");
System.out.println("Checking first entry");
System.out.println("First entry is: "+ treemap.firstEntry());
}
}
让我们编译并运行上面的程序,这将产生以下结果.
Checking first entry First entry is: 1=one

