Map<String, List<Model>> map = new HashMap<>();
// 如何获取相同的num 的对象做运算
for (Model model6 : list) { String s = model6.getNum(); if (map.containsKey(s)) { map.get(s).add(model6); } else { ArrayList<Model> NumList = new ArrayList<Model>(); NumList.add(model6); map.put(s, NumList); } }
Map<String, List<Model>> result = list.stream().collect(Collectors.groupingBy(e -> e.getB()));
结果集为List如何转为Map<String,List<Entity>>?
原文:https://www.cnblogs.com/banxianer/p/14227911.html