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.

10
  • 72
    The second one. A proper function should have no side effects, in your first implementation you are modifying the external world. Commented Feb 4, 2015 at 10:32
  • 47
    just a matter of style, but elt -> elt != null can be replaced with Objects::nonNull
    – the8472
    Commented Feb 4, 2015 at 10:40
  • 2
    @the8472 Even better would be to make sure there are no null values in the collection in the first place, and use Optional<T> instead in combination with flatMap.
    – herman
    Commented Feb 4, 2015 at 10:47
  • 2
    @SzymonRoziewski, not quite. For something as trivial as this, the work needed to setup the parallelstream under the hood will make using this construct mute.
    – user3248346
    Commented Feb 4, 2015 at 10:48
  • 2
    Note that you can write .map(this::doSomething) assuming that doSomething is a non-static method. If it's static you can replace this with the class name.
    – herman
    Commented Feb 4, 2015 at 11:55