• @MagicShel
    link
    5
    edit-2
    5 hours ago

    I try to prefer .findAny() over .findFirst() because it will perform better in some cases (it will have to resolve whether they are other matches and which one is actually first before they can terminate - more relevant for parallel streams I think. findAny short circuits that) but otherwise I like the first. I’d probably go with some sort of composed predicate for the second, to be able to easily add new criteria. But I could be over engineering.

    I mostly just posted because I think not enough people are aware of the reasons to use findAny as a default unless findFirst is needed.

    • magic_lobster_party
      link
      fedilink
      55 hours ago

      For me I have the habit of doing findFirst because determinism is important where I work. But I agree with you if determinism is not of importance.