Move to next item using Java 8 foreach loop in stream

后端 未结 4 564
醉话见心
醉话见心 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:45

    Another solution: go through a filter with your inverted conditions : Example :

    if(subscribtion.isOnce() && subscribtion.isCalled()){
                    continue;
    }
    

    can be replaced with

    .filter(s -> !(s.isOnce() && s.isCalled()))
    

    The most straightforward approach seem to be using "return;" though.

提交回复
热议问题