Java Stream() 流根据对象属性去重

// 引入了两个静态方法,以及通过 TreeSet<> 来达到获取不同元素的效果
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toCollection;
List<ChargeStudentItemDetailedVo> resultList = chargeStudentItemDetailedVos.stream().collect(
collectingAndThen(
toCollection(()-> new TreeSet<>(Comparator.comparing(ChargeStudentItemDetailedVo::getItemId))),
ArrayList::new
)
);

  

原文地址:https://www.cnblogs.com/lucky-jun/p/15029505.html