是否可以通过使用 Groovy 闭包或内置功能的列表元素添加来实现?使用加法运算符会导致简单的列表串联。
def firstList = [1, 2, 3, 4]
def secondList = [5, 6, 7, 8]
def resultList = firstList + secondList // It has to be by elements addition closure here
assert resultList == [6, 8, 10, 12] // Assertion failed
最佳答案
[ firstList, secondList ].transpose()*.sum()
关于list - Groovy中如何实现列表的元素添加?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24914608/