GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Monday, December 20, 2010

Map In Groovy

Groovy has a built in map data structure. To define it, use:
groovy>> data = ["bill": "gates", "steve": "jobs", "aura": "kasih"]

If you want to add an element to the map, use:
groovy>> data["lady"] = "gaga"
or
groovy>> data.lady = "gaga"

To access an element of the map, use:
groovy>> println data["lady"]
or
groovy>> println data.lady

To get the size of the data, type:
groovy>> data.size()

To create an empty map, type:
groovy>> data = [:]


Share/Bookmark

No comments:

Post a Comment