【发布时间】:2019-08-04 17:15:50
【问题描述】:
我的 java 代码中有一个“for of”,我尝试使用 lambda 表达式转换为“for each”。
for (Bicycle element : bicycleList) {
txtOutput.append("Model:" + element.getModel() + "\n");
}
我已经尝试过这样做:
bicycleList.forEach(txtOutput.append -> ("Model:" + bicycle.getModel() + "\n"));
谁能帮帮我?
【问题讨论】:
-
我建议
reduce(可能需要map)。看看Stream API
标签: java for-loop arraylist lambda foreach