java8根据某个属性去重

public static  Predicate distinctByKey(Function keyExtractor) {
    Map seen = new ConcurrentHashMap<>();
    return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}
list.stream().filter(distinctByKey(AiCategorySelectVo::getId)).collect(Collectors.toList());

你可能感兴趣的:(杂七杂八)