Groovy Method to combine list of lists
ListGroovyList Problem Overview
Input >> list = [[1,2,3], [6], [3,4,5,6]]
Output >> [1,2,3,3,4,5,6,6]
I want to know if there is something more straightforward than this
l = []
list.each{ l = l + it }
println l
like a default groovy closure or method?
List Solutions
Solution 1 - List
Try flatten
, ie:
list.flatten()
Or, to get the output you want:
list = [[1,2,3], [6], [3,4,5,6]]
assert list.flatten().sort() == [1,2,3,3,4,5,6,6]