views:

41

answers:

1

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?

+2  A: 

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}
ZeissS
That seems to do that job, thanks. Guess I should have tried that before asking ;)
StartingGroovy
Just for fun: `map.'Title of Book'` works as well ;)
ZeissS