jason
jason

Reputation: 355

How to separate List elements with commas in 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?

Upvotes: 7

Views: 3100

Answers (1)

jason
jason

Reputation: 355

names.join(",")

Upvotes: 19

Related Questions