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
Post a Comment