拥有此代码:
public Map<Job, Collection<JobTransform>> getPartitioning() {
Map<Job, Collection<JobTransform>> partitioning = new IdentityHashMap<>();
for (JobTransform jobTransform : content) {
Job job = jobTransform.getJob();
Collection<JobTransform> collection = partitioning.get(job);
if (collection == null) {
collection = new LinkedList<>();
partitioning.put(job, collection);
}
collection.add(jobTransform);
}
return partitioning;
}
和'content'是实现此方法的类的构造函数参数,如何使用Java中的Stream API将for-each循环转换为代码?现在我只有
content.stream().map(JobTransform::getJob)
我不知道如何进一步使用每项工作。我使用API错了吗?请帮我改进我的代码!
答案 0 :(得分:4)
$ mkdir -p .source/wall/model/bottom.png
$ make -f test.mk wall/red
running: wall/red/top.png
running: wall/red/bottom.png
running: wall/red
这与非流代码完全相同。