今天无意中发现一个遍历map的方法,给大家参考一下:
public static void main(String[] args) {
Map<String, String> map=new HashMap<String, String>();
map.put("a", "1111");
map.put("b", "222");
for(Entry<String, String> e:map.entrySet()){
System.out.println(e.getKey());
System.out.println(e.getValue());
}
}
遍历Map的新方法
本文介绍了一种遍历Java中Map集合的新方法。通过使用增强型for循环和entrySet()方法,可以更简洁地遍历并打印Map中的键值对。

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



