//去重
msgs = msgs.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Msg :: getMsgId))), ArrayList::new));
Stream流根据对象的某个字段去重
最新推荐文章于 2024-07-02 15:06:34 发布
//去重
msgs = msgs.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Msg :: getMsgId))), ArrayList::new));