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;
}
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
12
down voteaccepted
|
try and if you want an array:
Or, more groovy-ish:
|
Get the last key of a Map
map.keySet().last() or map.keySet()[-1]
Get sub-map consists of the last key-value of a Map
map.subMap(map.keySet().last())
Get sub-map except the last key-value
map.minus(map.subMap(map.keySet().last()))
Get the last item of a list
list.last()
Get the sub-list without the last element
list.take(list.size()-1) or list[0..list.size()-1]