private List listSort(List effectiveCoupon) {
List newList = effectiveCoupon.stream().sorted(Comparator
.comparing(CouponStatusInfo::getEndTime)
.thenComparing(CouponStatusInfo::getStartTime, Comparator.reverseOrder())
).filter(distinctByKey(item->item.getActivityId())).collect(Collectors.toList());
log.debug("---listSort.newList: {}", newList);
return newList;
}
private static Predicate distinctByKey(Function super T, ?> keyExtractor) {
Set
第二种写法
ListnewList = items.stream().sorted(Comparator .comparingLong(CouponStatusInfo::getEndTime) .thenComparing(CouponStatusInfo::getStartTime,Comparator.reverseOrder()) ).filter(distinctByKey(item->item.getActivityId())).collect(Collectors.toList()); } public static Predicate distinctByKey(Function super T, ?> keyExtractor) { Map
下面的代码可以理解为:
Map
Map api // 如果所指定的 key 已经在 HashMap 中存在,返回和这个 key 值对应的 value, 如果所指定的 key 不在 HashMap 中存在,则返回 null。 putIfAbsent



