JavaEE | 集合嵌套 HashMap 嵌套 HashMap、HashMap 嵌套 ArrayList、ArrayList 嵌套 HashMap
- HashMap 嵌套 HashMap
- HashMap 嵌套 ArrayList
- ArrayList 嵌套 HashMap
- ArrayList 嵌套ArrayList
1. HashMap 嵌套 HashMap
HashMap<String, Integer> subMap1 = new HashMap<>();
subMap1.put("张三",20);
subMap1.put("李四",22);
HashMap<String, Integer> subMap2 = new HashMap<>();
subMap2.put("王五",21);
subMap2.put("赵六",23);
HashMap<String, HashMap<String, Integer>> map = new HashMap<>();
map.put("A班",subMap1);
map.put("B班",subMap2);
Set<Map.Entry<String, HashMap<String, Integer>>> entries = map.entrySet();
for (Map.Entry<String, HashMap<String, Integer>> entry : entries) {
String key = entry.getKey();
System.out.println(key);
HashMap<String, Integer> value = entry.getValue();
Set<Map.Entry<String, Integer