list集合根据对象属性去重以及根据对象某个属性逆序排序,相同则使用另一个进行排序

去重:

couponInfos.addAll(couponInfoList);
couponInfos = couponInfos.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CouponInfo::getCouponInfoId))), ArrayList::new));

排序:

couponInfos.sort(Comparator.comparing(CouponInfo::getCreateTime).reversed().thenComparing(CouponInfo::getIsExpire));

你可能感兴趣的:(开发日常)