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());
}