stream流去重,排序

stream流根据某一字段去重
list= list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(List:: getId))), ArrayList::new));
stream流升序
list=list.stream().sorted().collect(Collectors.toList());
stream流根据某一字段升序
list.stream().sorted(Comparator.comparing(List::getId()))
stream流降序
list.stream().sorted(Comparator.reverseOrder())
stream流根据某一字段降序
list.stream().sorted(Comparator.comparing(List::getId()).reversed())

你可能感兴趣的:(java,开发语言,后端,stream)