Loading...

January 17, 2010

Groovy Goodness: Create Elements in Collection Definition

Small things can make our lives easier. For example if we use Groovy we can create a new list or map with a list of elements directly. We don't have to use an add() method.

def list = [
    'one', 
    'two', 
    'three',
]

def map = [
    'groovy': 1.7,
    'mrhaki': 'hubert',
]

assert list
assert map