So, I have the following code in which I add some items to the list, sort them and print as a string.
def officeWorkers = [] officeWorkers << "Jim Halpert" officeWorkers << "Dwight Shrute" officeWorkers << "Toby Flenderson" officeWorkers.sort() println("I wish my co workers were ${officeWorkers.toString()}")
The resulting line has opening and closing brackets ('[', ']]') that I do not want ("I would like my employees to be [Dwight Shrut, Jim Halpert, Toby Flenderson]").
It seems that one way to remove these brackets is to use the String replacement function, as suggested here .
But what if the actual list that I use already contains brackets in the values, they will also be replaced.
So, is there a way to print this list as a string without displaying these brackets and without using the replace function?
source share