Reputation: 2860
I have a map in groovy that looks like the following...
def book = [Title of Book: "Groovy Recipes", Author: "Scott Davis", Number of Pages: "241"]
I add my each 'book' into a BookList and would like to be able to get each value later on but when I try something like...
BookList.Title of Book[0] //prints something like Title[0] instead of Groovy Recipes
So my question is, is there a way to get those key/values without changing the names of the keys?
Upvotes: 2
Views: 4172
Reputation: 12135
The following worked in the groovy shell. You just have to use the []
instead of the dot notation:
groovy:000> map = [:]
===> {}
groovy:000> map['Title of Book'] = "Adam Riese"
===> Adam Riese
groovy:000> map
===> {Title of Book=Adam Riese}
Upvotes: 7