javagroovyfunctional-programmingclosuresjava-stream

Groovy: what is analogue for java stream anyMatch


What is Groovy analogue for following operation?

list.stream().anyMatch(b -> b == 0); 

Solution

  • 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