进行自然排序

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; };
}