本帖最后由 叶征东 于 2012-9-21 11:35 编辑
HashMap<String,Integer> maps = new HashMap<String, Integer>();
maps.put("zxx", 26);
maps.put("lhm", 35);
maps.put("flx", 33);
----------------------------------------------------------------------------------------------------------------
//--------------------(1)
Set<Map.Entry<String , Integer>> entrySet = maps.entrySet();
for (Map.Entry<String, Integer> entry : entrySet) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
//--------------------(2)
Set<Entry<String , Integer>> entrySet1 = maps.entrySet();
for (Map.Entry<String, Integer> entry : entrySet1) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
//--------------------(3)
Set<Map.Entry<String , Integer>> entrySet2 = maps.entrySet();
for (Entry<String, Integer> entry : entrySet2) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
//--------------------(4)
Set<Entry<String , Integer>> entrySet3 = maps.entrySet();
for (Entry<String, Integer> entry : entrySet3) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
(1),(2),(3),(4)除了红色的部分,其它的都是一样的.
(1),(2),(3),(4)输出的结果都是一样的.
本来是想写成(1)的样子的,结果不小心写成了(3)的样子,发现结果一样,就把(2)和(4)也试了一下.
(1),(2),(3),(4)有区别么?如果有,能给我讲讲么?谢谢.
|