java8 按照对象属性去重

没有其他代码,只有这一句

private static  Predicate distinctByKey(Function keyExtractor) {
        Map seen = new ConcurrentHashMap<>();
        return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}

使用嘛。。。

List entityList = List.stream().filter(distinctByKey(Entity::getAttribute))..collect(Collectors.toList());
字段 含义
Entity 对象实体
Attribute 属性

你可能感兴趣的:(java8 按照对象属性去重)