What is Groovy analogue for following operation?
list.stream().anyMatch(b -> b == 0);
Groovy syntax has a spectrum that ranges from Java-esque to idiomatic Groovy. Both of these work:
// Java-esque
List<Integer> list = [4,3,2,1,0]
assert list.stream().any{ b -> b == 0 }
// Groovier (note `it` is an alias for the parameter)
def list2 = [4,3,2,1,0]
assert list2.stream().any{ it == 0 }
You mean to find if the list contains element 0
?
def list = [0,1,2,3,4]
def result = list.any{it == 0}
println result
You can quickly try it online demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With