groovy中单个数组的列表

pra*_*tas 1 grails groovy

我有一个名为allproiListgrails 的列表,其中包含本身就是数字数组的元素.

我想将列表数组的所有单个数字放入一个集合中.

我怎么能在groovy中这样做?

Igo*_*nov 5

试试这个:

//input
def allproiList = [[1, 2], [3, 4], [4, 5, 7, 8], [2, 5, 6]]

//transform to Set
Set numsOnly = allproiList.flatten() as Set

//or if you just need List of uniq elements, you could do
//List numsOnly == allproiList.flatten().unique()

//check result
assert numsOnly.sort() == [1, 2, 3, 4, 5, 6, 7, 8]
Run Code Online (Sandbox Code Playgroud)