Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to separate List elements with commas in Groovy?

Tags:

list

groovy

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

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

println n

Output:

myname,yourname,theirname,allnames,

How do I get rid of the trailing comma?

like image 258
jason Avatar asked Jun 22 '10 15:06

jason


1 Answers

names.join(",")
like image 142
jason Avatar answered Sep 20 '22 09:09

jason