1、集合嵌套—案例引入
这里80就整成4个就行,不用太多。
package com.itheima.d3_map;
import java.util.*;
public class MapQianTao {
public static void main(String[] args) {
Map<String, List<String>> select = new HashMap<>();
List<String> list1 = new ArrayList<>();
Collections.addAll(list1,"A","B","C");
select.put("张三",list1);
List<String> list2 = new ArrayList<>();
Collections.addAll(list2,"A","C","D");
select.put("李四",list2);
List<String> list3 = new ArrayList<>();
Collections.addAll(list3,"B","D","E");
select.put("王5",list3);
System.out.println(select);
Map<String, Integer> map = new HashMap<>();
Set<Map.Entry<String,List<String>>> set = select.entrySet();
for (Map.Entry<String, List<String>> stringListEntry : set) {
List<String> l1 = stringListEntry.getValue();
for (String s : l1) {
if(map.containsKey(s)){
map.put(s, map.get(s)+1);
}else {
map.put(s,1);
}
}
}
System.out.println(map);
}
}
|