groovy Create a new list using collect


Example

def lst = ['foo', 'bar', 'baz']
lst.collect { it } // ['foo', 'bar', 'baz']

lst.collect { it.toUpperCase() } // ['FOO', 'BAR', 'BAZ']

To collect keys or values from a maps

def map = [foo: 'FOO', bar: 'BAR', baz: 'BAZ']
def keys = map.collect { it.key } // ['foo', 'bar', 'baz']
def vals = map.collect { it.value } // ['FOO', 'BAR', 'BAZ']

The above example is equivalent to calling map.keySet() and map.values()