//JDK1.5
Map map = new HashMap();
for(Object obj : map.keySet()) {
Object key = obj;
Object value = map.get(obj);
}
1
2
3
4
5
6
//JDK1.4
Map map = new HashMap() ;
Iterator iter = map.entrySet().iterator();
while(iter.hasNext()) {
Map.Entry entry = (Map.Entry)iter.next();
Object key = entry.getKey();
Object value = entry.getValue();
}
1
2
3
4
5
6
7
8
第一种:
Map map = new HashMap();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
}
1
2
3
4
5
6
7
效率高,以后要使用此种方式!
第二种:
Map map = new HashMap();
Iterator iter = map.keySet().iterator();
while (iter.hasNext()) {
Object key = iter.next();
Object val = map.get(key);
}
1
2
3
4
5
6
效率低,以后尽量少使用!
————————————————
版权声明:本文为CSDN博主「小程爱工作」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/seeseeyoua/article/details/118361605