53
Input >> list = [[1,2,3], [6], [3,4,5,6]]

Output >> [1,2,3,3,4,5,6,6] 

我想知道是否有比这更直接的东西

l = []
list.each{ l = l + it }
println l

像默认的 groovy 闭包或方法?

4

1 回答 1

92

尝试flatten,即:

list.flatten()

或者,要获得您想要的输出:

list = [[1,2,3], [6], [3,4,5,6]]

assert list.flatten().sort() == [1,2,3,3,4,5,6,6] 
于 2012-07-19T10:11:47.517 回答