0

I have a class

public class RegulatoryApproval {

    private String approvalType;
    private Boolean deleted;
    private RegulatorCategory regulatorCategory;
    //getters and setters

}

Another Class

public class RegulatorCategory {
    ...
    private List<CreditReportingField> creditReportingFields;
    //getters and setters
}

I am getting List of RegulatoryApproval. And I want to collect all CreditReportingFields in RegulatorCategory in one list. I am trying but I am stucking how to do it.

I am getting error

Type mismatch: cannot convert from List<Stream<CreditReportingField>> to List<CreditReportingField>

Here what I am doing

List<CreditReportingField> creditReportingFields = null;

List<RegulatoryApproval> regulatoryApprovals = regulatoryApprovalRepository.findDistinctByIdInAndDeletedFalse(courseApprovalIds);
    if (!CollectionUtils.isEmpty(regulatoryApprovals)) {
        creditReportingFields = regulatoryApprovals
        .stream()
        .map(RegulatoryApproval::getRegulatorCategory)
        .filter(p -> p!= null)
        .map(RegulatorCategory::getCreditReportingFields)
        .filter(p -> !CollectionUtils.isEmpty(p))
        .map(p -> p.
                stream()
                .filter(creditReportingField -> creditReportingField != null)
                //.collect(Collectors.toList())
        )
        .collect(Collectors.toList());
    }

How can I collect it ? Is this approach is right or there is better approach to do it ?

Thanks

Basit
  • 8,158
  • 43
  • 107
  • 190

0 Answers0