Move to next item using Java 8 foreach loop in stream

后端 未结 4 566
醉话见心
醉话见心 2020-12-04 17:17

I have a problem with the stream of Java 8 foreach attempting to move on next item in loop. I cannot set the command like continue;, only return; w

4条回答
  •  自闭症患者
    2020-12-04 17:46

    The lambda you are passing to forEach() is evaluated for each element received from the stream. The iteration itself is not visible from within the scope of the lambda, so you cannot continue it as if forEach() were a C preprocessor macro. Instead, you can conditionally skip the rest of the statements in it.

提交回复
热议问题