Groovy: Add prefix to each String in a List -



Groovy: Add prefix to each String in a List -

given next list:

list<string> list = ["test1", "test2", "test3"]

now want create 1 string out of list in next format:

"pre/test1 pre/test2 pre/test3"

so thought go next way:

println list.each { "pre/$it" }.join(' ')

however, leads next output:

"test1 test2 test3"

(note missing prefixes.) how can accomplish desired string concatenation in groovy?

def joined = ["test1", "test2", "test3"].collect { "pre/$it" }.join(' ')

each returns unmodified collection - whereas collect returns collection modified content.

groovy

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -