Map集合的遍历方法
作者:互联网
Map集合的遍历方法
keySet增强for
Set set = map.keySet();
for (Object key : set) {
System.out.println(key + "-" + map.get(key));
}
迭代器
Set set = map.keySet();
Iterator iterator = set.iterator();
while (iterator.hasNext()) {
Object key = iterator.next();
System.out.println(key + "-" + map.get(key));
}
直接获取value
Collection values = map.values();
System.out.println(values);
entrySet
Set<Map.Entry> entrySet = map.entrySet();
for (Map.Entry entry : entrySet) {
System.out.println(entry.getKey() + "-" + entry.getValue());
}
标签:Map,遍历,iterator,map,entrySet,System,set,key,集合 来源: https://blog.csdn.net/weixin_44717965/article/details/120237528