Reputation: 5733
Is there a more simple and performant way of doing this, At the end I would need a list of scheduleContainers (List<ScheduleContainer>)
final List<ScheduleResponseContent> scheduleResponseContents = new ArrayList<>();
scheduleResponseWrappers.parallelStream().forEach(srw -> scheduleResponseContents.addAll(srw.getScheduleResponseContents()));
final List<List<ScheduleContainer>> schedulesOfWeek = new ArrayList<>();
scheduleResponseContents.parallelStream().forEach(src -> schedulesOfWeek.addAll(src.getSchedules()));
final List<ScheduleContainer> schedules = new ArrayList<>();
schedulesOfWeek.parallelStream().forEach(s -> schedules.addAll(s));
Upvotes: 0
Views: 990
Reputation: 106
Because of missing classes, I can just assume this is correct:
final List<ScheduleContainer> schedules = scheduleResponseWrappers.stream()
.flatMap(srw -> srw.getScheduleResponseContents().stream())
.flatMap(src -> src.getSchedules().stream())
.collect(Collectors.toList());
Upvotes: 1