stream流中根据单条件或多条件过滤

时间:2021-09-03 18:19:00   收藏:0   阅读:18
public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
Map<Object,Boolean> seen = new ConcurrentHashMap<>();
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}

例子:
list.stream.filter(distinctByKey(a->a.getParam));

原文:https://www.cnblogs.com/DarkerbeS/p/15222584.html

评论(0)
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!