After the value of List to Map in Java8 is repeated, the method of merging the value into a List

It was originally a set of menus, then grouped by parent node, and merged all child nodes into a list

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;
}));

  

Guess you like

Origin www.cnblogs.com/coding88/p/12748945.html