开发者

Groovy map - keys with space

开发者 https://www.devze.com 2023-01-10 04:56 出处:网络
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 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?


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}
0

精彩评论

暂无评论...
验证码 换一张
取 消