How to iterate nested lists with lambda streams?

前端 未结 6 1836
眼角桃花
眼角桃花 2021-02-12 20:16

I\'m trying to refactor the following code to lambda expressions with `stream, especially the nested foreach loops:

public static Result match (Response rsp) {
          


        
6条回答
  •  死守一世寂寞
    2021-02-12 20:23

    You can iterate nested loops like below

    allAssessmentsForJob.getBody().stream().forEach(assessment -> {
            jobAssessments.stream().forEach(jobAssessment -> {
                if (assessment.getId() == jobAssessment.getAssessmentId()) {
                    jobAssessment.setAssessment(assessment);
                }
            });
        });
    

提交回复
热议问题