如何按照java8转换此代码,使其在父列表中具有内部列表并进行过滤?
for(A aobj: branchList) {
for(C cobj : aobj.getCList()) {
if(!enteredBranchId.equals(cobj.getId())
myList.add(aobj.getId());
}
}
答案 0 :(得分:2)
myList = branchList.stream()
.map(b -> b.getSubBranches())
.flatMap(Collection::stream)
.filter(sb -> !enteredBranchId.equals(sb.getBranchId()))
.collect(Collectors.toList());