首页 > 解决方案 > Groovy:插入文本的字符串列表丢失撇号

问题描述

我想创建一个文本,在其中插入一个 stings 列表 ["aa","bb"]。

def texts = ["aa" , "bb"]
def out = "my list: $texts"
println out

我希望输出为:

我的清单:["aa","bb"]

但我得到的输出是:

我的清单:[aa, bb]

我该如何解决这个问题?

标签: groovystring-interpolation

解决方案


The result of texts.toString() does not include the quotation marks. So you have to create that output yourself:

def out = "my list: ${texts.collect{'"' + it + '"'}}"

推荐阅读