【发布时间】:2015-06-30 05:45:03
【问题描述】:
我还在学习Lambda,如果做错了请见谅
final Long tempId = 12345L;
List<Entry> updatedEntries = new LinkedList<>();
for (Entry entry : entryList) {
entry.setTempId(tempId);
updatedEntries.add(entityManager.update(entry, entry.getId()));
}
//entryList.stream().forEach(entry -> entry.setTempId(tempId));
似乎forEach 只能针对一条语句执行。它不会返回更新的流或函数以进一步处理。我可能完全选错了。
有人可以指导我如何有效地做到这一点吗?
还有一个问题,
public void doSomething() throws Exception {
for(Entry entry: entryList){
if(entry.getA() == null){
printA() throws Exception;
}
if(entry.getB() == null){
printB() throws Exception;
}
if(entry.getC() == null){
printC() throws Exception;
}
}
}
//entryList.stream().filter(entry -> entry.getA() == null).forEach(entry -> printA()); something like this?
如何将其转换为 Lambda 表达式?
【问题讨论】: