Grooviest way to join collection of Strings in Groovy 2.x

You can use the Iterator variation of the join method in DefaultGroovyMethods. It’s signature is the same, only the separator needs to be passed in.

It would look like this:

List<String> values = ["string1", "string2", "string3"]
String joinedValues = values.join(",")

Or you can do it all on one line:

String joinedValues = ["string1", "string2", "string3"].join(",")

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)