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 闭包或方法?
尝试flatten
,即:
list.flatten()
或者,要获得您想要的输出:
list = [[1,2,3], [6], [3,4,5,6]]
assert list.flatten().sort() == [1,2,3,3,4,5,6,6]