我有2个课程,这是
public class TimeCardResponse {
private String login;
List<TimeCardDetail> timeCardDetails;
}
这:
public TimeCardDetail(String workingDay, Float workingTime) {
this.workingDay = workingDay;
this.workingTime = workingTime;
}
input : a List<TimeCardResponse>
我想在workingDay
中获得类TimeCardDetail
的所有List<String>
,并在Java 8中使用Stream
。
答案 0 :(得分:0)
List<String> workingDays = a.stream().map(TimeCardResponse::getTimeCardDetails)
.filter(x-> Objects::nonNull)
.flatMap(List::stream)
.map(TimeCardDetail::getWorkingDay).collect(toList());
答案 1 :(得分:0)
假设您有一些getWorkingDay
方法:
List<String> workDays = timeCardDetails.stream()
.map(TimeCardDetail::getWorkingDay)
.filter(Objects::nonNull) //filter out null values
.collect(Collectors.toList());
哪个会退回{@ {1}}的卡片工作时间