// 引入了两个静态方法,以及通过 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
)
);