Java8 根据对象某个属性值去重

list中的对象某个属性存在重复时将重复的对象去重

//根据skuAttrValueName值去重
            List<SkuValue> uniqueSkuValues = skuValues.stream().collect(
                    Collectors.collectingAndThen(Collectors.toCollection(
                            () -> new TreeSet<>(Comparator.comparing(o -> o.getSkuAttrValueName()))), ArrayList::new)
            );

猜你喜欢

转载自www.cnblogs.com/tongxuping/p/10930998.html