当前位置: 代码迷 >> 综合 >> Stream 根据某对象对属性去重
  详细解决方案

Stream 根据某对象对属性去重

热度:61   发布时间:2024-02-07 19:46:13.0
    //根据属性去重public <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(vo -> Stream.of(vo.getOrgName(),vo.getUserName()).toArray())).collect(Collectors.toList());

 

  相关解决方案