Saturday, 5 March 2016

How to get common elements in arrays of Groovy

Code:

class GroovyController {

def messageSource

def index(){
def array1 = [1,2,3,4,5]
def array2 = [3,4]
println 'Intersection of array1 and array2 : '+array1.intersect(array2)
render ''
}

}

Output:

Intersection of array1 and array2 : [3, 4]

No comments:

Post a Comment