Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 1
    Most of this answer is fine. But... I can see how filtering a collection could eliminate the need for continue statements, but I don't see how they help much with break. Commented Feb 27, 2018 at 20:55
  • 1
    @user949300 A takeWhile filter can replace break statements. If you have one - Java for example only gets them at Jave 9 (not that it's that hard to implement it yourself) Commented Feb 28, 2018 at 1:35
  • 1
    But in Java you still can filter before the iteration. Using streams (1.8 or later) or using Apache Collections (1.7 or earlier). Commented Feb 28, 2018 at 6:44
  • @IdanArye - there are add-on libraries that add such facilities to the Java streams API (e.g. JOO-lambda) Commented Feb 28, 2018 at 17:41
  • @IdanArye never heard of a takeWhile before your comment. Explicitly linking the filter to an ordering strikes me as unusual and hacky, since in a "normal" filter every element gets to return true or false, independent of what comes before or after. In this way you can run things in parallel. Commented Mar 2, 2018 at 19:55