The groovy way to see if something is in a list is to use \"in\"
if(\'b\' in [\'a\',\'b\',\'c\'])
However how do you nicely see if something
The contains(string) method is nice and simple to read if something is contained or not contained in the list to be checked against. Take a look the example below for more insight.
EXAMPLE
//Any data you are looking to filter
List someData = ['a', 'f', 'b', 'c', 'o', 'o']
//A filter/conditions to not match or match against
List myFilter = ['a', 'b', 'c']
//Some variables for this example
String filtered, unfiltered
//Loop the data and filter for not contains or contains
someData.each {
if (!myFilter.contains(it)){
unfiltered += it
} else {
filtered += it
}
}
assert unfiltered = "foo"
assert filtered = "abc"
CONTAINS( )
Parameters: text - a String to look for.
Returns: true if this string contains the given text
source