java8 lambda groupingby 分组保持原来顺序

300 阅读1分钟
returnRemindList.stream()
.collect(Collectors.groupingBy(TopicRemindSettingBO::getRemindPhone,
 LinkedHashMap::new, Collectors.toCollection(ArrayList::new)));

returnRemindList 是已经排序好序的集合,groupingBy 分组后map是不保持有序, 加入如下2个参数可以保持原来的顺序输出 LinkedHashMap::new,Collectors.toCollection(ArrayList::new)\color{red}{LinkedHashMap::new, Collectors.toCollection(ArrayList::new)}

原文地址:blog.csdn.net/weixin_4594…