Groovy Method to combine list of lists

ListGroovy

List 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] 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVamsi EmaniView Question on Stackoverflow
Solution 1 - Listtim_yatesView Answer on Stackoverflow