Java8List转Map的value冲突重复将value合并成List解决
原文链接: https://www.cnblogs.com/coding88/p/12748945.html
本来是一个菜单集合,然后按父节点分组,将子节点全部合并到一个list中
1
2
3
4
5
6
7
|
List<SysMenu> menuList = new ArrayList<>(); Map<String, List<SysMenu>> menuMap = menutList.stream().collect(Collectors.toMap(SysMenu::getParentId, menuObj -> Lists.newArrayList(menuObj), (List<SysMenu> newValueList, List<SysMenu> oldValueList) -> { oldValueList.addAll(newValueList); return oldValueList; })); |