当在Iterable上使用外部迭代时,我们使用break或return from enhanced for-each循环,如下:
for (SomeObject obj : someObjects) {
if (some_condition_met) {
break; // or return obj
}
}
如何在Java 8 lambda表达式中使用内部迭代中断或返回:
someObjects.forEach(obj -> {
//what to do here?
})