user797963
user797963

Reputation: 3027

Groovy - for loops in mutli-line strings?

How can I loop through a list of values, including each one into a Groovy multi-line string?

Example

myList = ['one', 'two', 'three']
myString = """
           some text
           ${for(item in myList){item}}
           some more text
           """

Upvotes: 1

Views: 528

Answers (1)

m0skit0
m0skit0

Reputation: 25873

Using List.join

static void main(String[] args) {
    def myList = ['one', 'two', 'three']
    def myString = """
       some text
       ${myList.join()}
       some more text
       """
    println myString
}

Upvotes: 1

Related Questions