Bootstrap

使用stream流完成去重操作

使用stream流完成去重操作

仅用作笔记记录

List<MM0001> collect1 = mm0001List.stream()
.filter(distinctByKey(MM0001::getMatNo))
.collect(Collectors.toList());
private <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
        Map<Object, Boolean> seen = new ConcurrentHashMap<>();
        return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
    }
;