Wednesday 23 January 2019

Groovy: List: findAll: Find all the elements that matches to given criteria


public Collection findAll(Closure closure)
Return a collection that matches to thi closure.

HelloWorld.groovy

numbers = [2, 5, 8, 1, 32, 49, 65, 43, 70, 21, 42]

def numberDivisibleBy7 = numbers.findAll { it % 7 == 0}

println "Numbers in the list $numbers that are divisible by 7 are : $numberDivisibleBy7"

Output
Numbers in the list [2, 5, 8, 1, 32, 49, 65, 43, 70, 21, 42] that are divisible by 7 are : [49, 70, 21, 42]


Previous                                                 Next                                                 Home

No comments:

Post a Comment