Adding the same string to a list of strings in Groovy
I want to add a line to every line in a list of lines. I wanted to do something like this
def a = 'a '
def b = 'b '
[a,b].each {
it += 'yo'
}
assertEquals a, 'a yo'
assertEquals b, 'b yo'
But obviously it won't work.
+3
David Sawyer
source
to share
1 answer
You can do
(a,b) = [a,b].collect { "$it yo" }
+8
tim_yates
source
to share