1. 使用Map.Entry遍历
Map<String, ArrayList<String>> map = new HashMap<>();
for (Map.Entry<String, ArrayList<String>> entry : map.entrySet()) {
String key = entry.getKey();
ArrayList<String> item = entry.getValue();
// ....
}
for (String s : map.keySet()) {
// ...
}
for (ArrayList<String> e : map.values()) {
// ...
}
3. 使用Iterator
Map<Integer, Integer> map = new HashMap<>();
Iterator<Map.Entry<Integer, Integer>> entries = map.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<Integer, Integer> entry = entries.next();
// ...
}
Map<Integer, Integer> map = new HashMap<>();
for (Integer key : map.keySet()) {
Integer value = map.get(key);
// ...
}