HashMap h = new HashMap();
h.put("1","1aaaa");
h.put("2","2222");
Iterator it = h.keySet().iterator();
while(it.hasNext()){
Object obj = it.next();
System.out.println(obj + ": "+h.get(obj));
}
System.out.println("==============================");
it = h.keySet().iterator();
while(it.hasNext()){
Object obj = it.next();
System.out.println(obj + ": "+h.get(obj));
}
这样就好
需要注意的是
如果多线程访问这个HashMap,并且可能有修改,就需要
sychronize(h{)
it = h.keySet().iterator();
while(it.hasNext()){
Object obj = it.next();
System.out.println(obj + ": "+h.get(obj));
}
Iterator 遍历map的方法
最新推荐文章于 2024-05-29 11:26:00 发布