// 引入了兩個靜態方法,以及通過 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
)
);
