ThanosF ThanosF - 7 months ago 67
Groovy Question

Add double quotes to list of strings

I've got a list in groovy lets say:

[one, two, three]

Now I want to add double quotes to the strings of this array so that the final result would be:

["one", "two", "three"]

Note that I do want the square brackets to be included as well. How can I do that in Groovy in the most comprehensive way?

EDIT: I'm using groovy templating inside html code and I just want a string in the exact format I described above


so if you have:

def list = ['one', 'two', 'three']

Then you can do:

List modifiedList = list.collect{ '"' + it + '"'}

output : ["one", "two", "three"]