Java程序以获取存储在TreeMap中的最高键
使用该lastKey()方法获取存储在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.lastKey()
以下是获取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("Highest key in TreeMap: " + m.lastKey());
}
}输出结果
TreeMap Elements...
{1=PHP, 2=jQuery, 3=JavaScript, 4=Ruby, 5=Java, 6=AngularJS, 7=ExpressJS}
Highest key in TreeMap: 7热门推荐
10 猪年元旦祝福语简短创意
11 生日祝福语简短独特格式
12 14年祝福语简短情话
13 年底老板祝福语简短的
14 高考毕业祝福语简短励志
15 新年祝福语长辈简短红包
16 哥哥新婚祝福语创意简短
17 朋友结婚致辞祝福语简短
18 员工对同事祝福语简短