Groovy provides ‘flatten’ method, it flattens nested
collections in this list.
HelloWorld.groovy
list = [1, [2, 3], [4, [5, [6, 7, [8, 9]]]]] flattenList = list.flatten() println "list : $list" println "flattenList : $flattenList"
Output
list : [1, [2, 3], [4, [5, [6, 7, [8, 9]]]]]
flattenList : [1, 2, 3, 4, 5, 6, 7, 8, 9]
flattenList : [1, 2, 3, 4, 5, 6, 7, 8, 9]
No comments:
Post a Comment