获取存储在Java TreeMap中的最低键
使用该firstKey()方法获取存储在TreeMap中的最低键。
让我们首先设置TreeMap并向其中添加一些元素-
TreeMap<Integer,String> m = new TreeMap<Integer,String>(); m.put(1,"PHP"); m.put(2,"jQuery"); m.put(3,"JavaScript"); m.put(4,"Ruby"); m.put(5,"Java"); m.put(6,"AngularJS"); m.put(7,"ExpressJS");
现在获得最低的钥匙-
m.firstKey()
以下是获取TreeMap中最低键的示例-
示例
import java.util.*;
public class Demo {
public static void main(String args[]) {
TreeMap<Integer,String> m = new TreeMap<Integer,String>();
m.put(1,"PHP");
m.put(2,"jQuery");
m.put(3,"JavaScript");
m.put(4,"Ruby");
m.put(5,"Java");
m.put(6,"AngularJS");
m.put(7,"ExpressJS");
System.out.println("TreeMap Elements...\n"+m);
System.out.println("Lowest key in TreeMap: " + m.firstKey());
}
}输出结果
TreeMap Elements...
{1=PHP, 2=jQuery, 3=JavaScript, 4=Ruby, 5=Java, 6=AngularJS, 7=ExpressJS}
Lowest key in TreeMap: 1热门推荐
2 甄嬛传祝福语简短
10 小孩想说的祝福语简短
11 舅舅大婚文案祝福语简短
12 初八的祝福语简短
13 入学校简短祝福语
14 今年节日祝福语简短
15 五十二新年祝福语简短
16 新婚祝福语简短十六字
17 预祝高尔夫的祝福语简短
18 宝宝祝福语诗意简短 古文