def personAgeMap = [matthew: 30, mark:25, luke: 40]
Since Groovy is just a superset of Java, we can use the put method to add an entry to a map.
We can also use a syntax similar to accessing an array. For example:
personAgeMap['Tim'] = 28
Another way is to treat the key as property of the map object. Example:
personAgeMap.Roy = 32
You can also use dot (.) followed by the key enclosed in quotes. Example:
personAgeMap.'Tim' = 55
Lastly, you can add entries coming from another map. You can push entries from one map to another, for example:
personAgeMap << [Michael:29]In summary, above are 5 ways of how to push an item in Groovy and add it to a map. There could be more ways in future version of Groovy.