//章节
//LinkedHashMap可以保持原有顺序
LinkedHashMap<String, List<ExerciseOutDto>> map = errexerciseOutDtos.stream()
.collect(Collectors.groupingBy(ExerciseOutDto::getExercise_type,LinkedHashMap::new,Collectors.toList()));
//处理返回数据
for (Map.Entry<String, List<ExerciseOutDto>> integerListEntry : map.entrySet())
{
ExerciseOutDto outDto = new ExerciseOutDto();
outDto.setExercise_type(integerListEntry.getKey());
outDto.setIds(integerListEntry.getValue().stream().map(ExerciseOutDto::getId).collect(Collectors.joining(",")));
errexerciseOutDtos.add(outDto);
}
分组求和
Map<Integer, IntSummaryStatistics> collect =list.stream().collect(Collectors.groupingBy
(Foo::getCode,Collectors.summarizingInt(Foo::getCount)));
//按照驾校分组求费用之和
Map<String, Integer> collect = failList.stream().collect(Collectors.groupingBy(MessageInstanceDataEntity::getSchoolId,
Collectors.summingInt(MessageInstanceDataEntity::getPrice)));