我想在字符串列表中的每个字符串后面添加一个字符串。我想要做的事情就像这样: def a = 'a ' def b = 'b ' [a,b].each { it += 'yo' } assertEquals a, 'a yo' assertEquals b, 'b yo' 但显然这样做行不通。
collect
。如果你真的必须/想要“添加”,你可以在每个元素上调用plus
。例如,通过扩展运算符:['a','b']*.plus(' yo')
- cfrick