Problembeschreibung:
Collectors.groupingBy-Out-of-Order-Problem nach der Gruppierung
Lösung:
Da Collectors.groupingBy nach der Gruppierung standardmäßig den HashMap-Typ zurückgibt, ändern Sie ihn einfach in LinkedHashMap.
// forumReplyList 集合是按照创建时间倒序的, groupBy 分组返回类型应该修改为LinkedHashMap,否则乱序
LinkedHashMap<Long, List<ForumReplyPO>> collect =
forumReplyList.stream()
.collect(
Collectors.groupingBy(
ForumReplyPO::getCommentId, LinkedHashMap::new, Collectors.toList()));