public class IteratorMap {
public static void main(String[] args) {
Map map = new HashMap();
map.put("test", "test");
map.put("name", "dahai");
for(Iterator it = map.entrySet().iterator();it.hasNext();){
Map.Entry entry = (Map.Entry)it.next();
Object key = entry.getKey();
Object val = entry.getValue();
}
}
}
遍历Map
最新推荐文章于 2023-08-08 09:03:57 发布
本文提供了一个Java示例程序,演示了如何通过Iterator来遍历Map集合,并获取其键值对。此示例使用了HashMap作为具体的Map实现。
392

被折叠的 条评论
为什么被折叠?



