Skip to content

Instantly share code, notes, and snippets.

@jiahut
Last active July 30, 2018 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiahut/fcbf27c46a5cd59b2ff31175eca56391 to your computer and use it in GitHub Desktop.
Save jiahut/fcbf27c46a5cd59b2ff31175eca56391 to your computer and use it in GitHub Desktop.
Difference between findAny() and findFirst() in Java 8
def l = Arrays.asList("B","A","C")
def r = l.stream().parallel().filter { e -> e != "B" } .findAny()
def s = l.stream().parallel().filter { it != "B"}.findFirst()
println l
println r.get() // something A or C
println s.get() // always A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment