java中怎么遍历HashMap
展开全部
可以遍历 map 的 entrySet 和 keySet
entrySet 的如
Set<Map.Entry<String, String>> entryseSet=map.entrySet();
for (Map.Entry<String, String> entry:entryseSet) {
System.out.println(entry.getKey()+","+entry.getValue());
}
keySet的是
Set<String> set = map.keySet();
for (String s:set) {
System.out.println(s+","+map.get(s));
}
entrySet 的如
Set<Map.Entry<String, String>> entryseSet=map.entrySet();
for (Map.Entry<String, String> entry:entryseSet) {
System.out.println(entry.getKey()+","+entry.getValue());
}
keySet的是
Set<String> set = map.keySet();
for (String s:set) {
System.out.println(s+","+map.get(s));
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询