在Java中检索TreeMap中的第一个条目
使用firstEntry()TreeMap中的方法检索第一个条目。
创建一个TreeMap并添加一些元素
TreeMap<Integer, String> m = new TreeMap<Integer, String>(); m.put(1,"India"); m.put(2,"US"); m.put(3,"Australia"); m.put(4,"Netherlands"); m.put(5,"Canada");
现在,检索第一个条目
m.firstEntry()
以下是在TreeMap中检索第一个条目的示例
示例
import java.util.*;
public class Demo {
public static void main(String args[]){
TreeMap<Integer, String> m = new TreeMap<Integer, String>();
m.put(1,"India");
m.put(2,"US");
m.put(3,"Australia");
m.put(4,"Netherlands");
m.put(5,"Canada");
for(Map.Entry e:m.entrySet()){
System.out.println(e.getKey()+" "+e.getValue());
}
System.out.println("First Entry in Map is "+m.firstEntry());
}
}输出结果
1 India 2 US 3 Australia 4 Netherlands 5 Canada First Entry in Map is 1=India
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短