David Sawyer
David Sawyer

Reputation: 557

Appending the same string to a list of strings in Groovy

I want to append a string to each string in a list of strings. I was wanting 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 that's not going to work.

Upvotes: 3

Views: 1004

Answers (1)

tim_yates
tim_yates

Reputation: 171164

You can do

(a,b) = [a,b].collect { "$it yo" }

Upvotes: 9

Related Questions