我有这段代码
列表与LT; BookDto> deskOfficer =
delegationExtendedDto 。流() .filter(对象::非空) .filter(d - > d.getMembers()!= …
你似乎在寻找 flatmap 如:
flatmap
List<BookDto> deskOfficer = delegationExtendedDto .stream() .filter(Objects::nonNull) .filter(d -> d.getMembers() != null) // stream would handle the empty case .flatmap(d -> d.getMembers().stream()) // <<< here -- the stream objects are different .filter(Objects::nonNull) .filter(m -> RolesEnum.RESPONSIBLE_ADMIN.equals(m.getRole()))) .collect(Collectors.toList());