如何在Groovy中用逗号分隔List元素?

时间:2010-06-22 15:24:13

标签: list groovy

def names = ["myname", "yourname", "theirname", "allnames"]

String n = ""
names.each{
    n += it + ","
}

println n

输出:

myname,yourname,theirname,allnames,

如何摆脱尾随的逗号?

1 个答案:

答案 0 :(得分:17)

names.join(",")