如何通过Groovy中的列表添加元素来实现?

时间:2014-07-23 15:24:58

标签: list groovy

是否可以通过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

1 个答案:

答案 0 :(得分:4)

[ firstList, secondList ].transpose()*.sum()