按照id分组构造 Map<String, SysDepart>
Map<String, SysDepart> sysDepartMap =
departList.stream().collect(
Collectors.groupingBy(SysDepart::getId,
Collectors.collectingAndThen(
Collectors.toList(),
sysDeparts -> sysDeparts.get(0))));
按照parentId分组构造 Map<String, List>
Map<String, List<SysDepart>> sysDepartListMap =
departList.stream().collect(
Collectors.groupingBy(SysDepart::getParentId));
按照id和日期一起分组(以“##”隔开)构造 Map<String, List>
Map<String,List<SysDepart>> sysDepartListMap =
departList.stream().collect(Collectors.groupingBy(
sysDepart ->
sysDepart.getId()+"##"+sysDepart.getCreateTime()));