【发布时间】:2016-03-02 09:45:48
【问题描述】:
我有一个ScheduleContainer 对象列表,并且在流中每个元素都应该转换为ScheduleIntervalContainer 类型。有没有办法做到这一点?
final List<ScheduleContainer> scheduleIntervalContainersReducedOfSameTimes
final List<List<ScheduleContainer>> scheduleIntervalContainerOfCurrentDay = new ArrayList<>(
scheduleIntervalContainersReducedOfSameTimes.stream()
.sorted(Comparator.comparing(ScheduleIntervalContainer::getStartDate).reversed())
.filter(s -> s.getStartDate().withTimeAtStartOfDay().isEqual(today.withTimeAtStartOfDay())).collect(Collectors
.groupingBy(ScheduleIntervalContainer::getStartDate, LinkedHashMap::new, Collectors.<ScheduleContainer> toList()))
.values());
【问题讨论】:
-
这还不清楚。请发帖minimal reproducible example。
-
你在四个小时前问了同样的问题。
-
最简单的方法是使用方法参考:
.map( ScheduleIntervalContainer.class::cast ),正如 Jon Skeet 在下面的评论中所建议的那样,以及 OP 稍后对一个相关但不同的问题的回答。跨度>