Map<String, List<introductionvideopagedto>> map = videoPageDtoList.stream().collect(Collectors.groupingBy(dto -> dto.getDataId()));</introductionvideopagedto>
"3": [ { "id": "96ab01d10d66bb0fe41d3fc65b7eeca4", "title": "视频标题", "videoUrl": "11111111111", "dataId": "3", "sort": 2, "createTime": 1564041929000 }, { "id": "ef510c786580637e831ea532e925a312", "title": "课程标题课程标题", "videoUrl": "222222222222", "dataId": "3", "sort": 3, "createTime": 1568791200000 }, { "id": "efa01867ea0d6cf4cccc0020203c6928", "title": "课程标题", "videoUrl": "333333333333333333333333333333333333333", "dataId": "3", "sort": 1, "createTime": 1568790906000 } ]
groupingBy 之后的这个 map 中 key stream 好像是默认已经排序了? 接着还想在组内对 sort 进行排序
1
ayonel 2019-09-23 19:01:04 +08:00
必须一步到位么?
https://stackoverflow.com/questions/29610465/sort-the-values-in-a-map-of-type-mapstring-liststring 这个两步可解决 第二步:map.values().stream().forEach(l->l.sort(Compartor)) 大概这样 |
2
zydxn 2019-09-23 19:39:26 +08:00
list.stream()
.sorted(Comparator.comparing(IntroductionVideoPageDTO::getSort)) .collect(Collectors.groupingBy(IntroductionVideoPageDTO::getDataId)); |