进行自然排序
Map<Long, List<HistoryComparisonVO>> result = new LinkedHashMap<>();
historyGroupMap.entrySet().stream()
.sorted(Map.Entry.comparingByKey()).forEachOrdered(x -> result.put(x.getKey(), x.getValue()));
进行倒序
Map<Long, List<HistoryComparisonVO>> result = new LinkedHashMap<>();
historyGroupMap.entrySet().stream()
.sorted(Collections.reverseOrder(Map.Entry.comparingByKey())).forEachOrdered(x -> result.put(x.getKey(), x.getValue()));
定义去重
historyList.stream().filter(distinctByKey()).collect(Collectors.toList());
private static Predicate<HistoryComparisonVO> distinctByKey(){
final Map<Object,HistoryComparisonVO> seen = new ConcurrentHashMap<>();
return history -> {
String key = history.getUserId() + "-" + history.getDisplayDeptCode() + "-" + history.getBatchId();
return seen.putIfAbsent(key,history) == null; };
}
- 本文链接: http://maltose.top/archives/map-gen-ju-key-jin-xing-pai-xu
- 版权声明: 本博客所有文章除特别声明外,均采用CC BY-NC-SA 3.0 许可协议。转载请注明出处!