您将如何将此代码重构为Streams?

for (ConditionEntity conditionEntity : dbData.getContent()) {
    AdminCondition adminCondition =
            dataEntityMapper.conditionEntitytoModel(conditionEntity);

    this.myService.addBasicInterest(adminCondition); // <=== this is my Problem
    conditionList.add(adminCondition);
}

到目前为止,我已经做到了:
dbData.getContent().stream()
    .map(conditionEntity -> dataEntityMapper.conditionEntitytoModel(conditionEntity))
    .collect(conditionList);

谢谢!

最佳答案

我希望采用以下解决方案:

List<ConditionEntity> conditions = dbData.getContent().stream()
        .map(dataEntityMapper::conditionEntitytoModel)
        .collect(Collectors.toList());

conditions.forEach(this::addBasicInterest);

09-26 15:10