groovy

How do I join the keys of a map in a string?


I want to return the keys of a map into a string like this:

mymap = [
    aaa: myObj.aaa,
    bbb: myObj.bbb,
    ccc: myObj.ccc
]

def list = [] 
mymap.each{ key, value -> key; list << key}
myStr = list.join('\\\n')

I could add them to an array and then join like this but is there a more groovy way to do this? Is there a language construct that can do this in one step?


Solution

  • You could use:

    mymap*.key?.join("\\\n")