Groovy Map Access

// Simple map.
def [name'mrhaki'language'Groovy']
 
assert 'mrhaki' == m.getAt('name')
assert 'mrhaki' == m['name']
assert 'Groovy' == m.language
assert 'mrhaki' == m."name"
assert 'mrhaki' == m.get('name')  // We can omit the default value if we know the key exists.
assert 'Groovy' == m.get('language''Java')
assert null == m.get('expression')  // Non-existing key in map.
assert 'rocks' == m.get('expression''rocks')  // Use default value, this also creates the key/value pair in the map.
assert 'rocks' ==  m.get('expression')

Comments

Popular posts from this blog

தட்டு வண்டியில் காளிக்கோயில் - சிறுகதை

பிரேமாவின் பெண் குழந்தை

தீபம் பிளக்ஸ்