public static Map mapMerge(List<Map> list) {
Map<Object, List> map = new HashMap<>();
for (Map m : list) {
Iterator<Object> it = m.keySet().iterator();
while (it.hasNext()) {
Object key = it.next();
if (!map.containsKey(key)) {
List newList = new ArrayList<>();
newList.add(m.get(key));
map.put(key, newList);
} else {
map.get(key).add(m.get(key));
}
}
}
return map;
}
java 合并两个map
于 2022-04-01 11:10:15 首次发布