banderson623 banderson623 - 1 month ago 7
Groovy Question

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

How do I figure out if an array contains an element?
I thought there might be something like

[1,2,3].includes(1)
which would evaluate as
true

Answer

.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')