Get key in groovy maps

2019-02-16 03:42发布

def map = [name:"Gromit", likes:"cheese", id:1234]

I would like to access map in such a way that I can get the key

something like the output should be

map.keys returns array of string. basically i just want to get the keys

output:

name
likes
id

标签: groovy maps
1条回答
Lonely孤独者°
2楼-- · 2019-02-16 04:19

try map.keySet()

and if you want an array:

map.keySet() as String[]; // thx @tim_yates

Or, more groovy-ish:

map.each{
    key, value -> print key;
}
查看更多
登录 后发表回答