How to check if element in groovy array/hash/collection/list? How to check if element in groovy array/hash/collection/list? arrays arrays

How to check if element in groovy array/hash/collection/list?


Some syntax sugar

1 in [1,2,3]


.contains() is the best method for lists, but for maps you will need to use .containsKey() or .containsValue()

[a:1,b:2,c:3].containsValue(3)[a:1,b:2,c:3].containsKey('a')


For lists, use contains:

[1,2,3].contains(1) == true