Groovy List<Map> Flatten: How to Combine Maps into a Single List
In Groovy, you can use the flatten() method to flatten a list of maps. Here is an example:
def listOfMaps = [
[name: \'John\', age: 25],
[name: \'Jane\', age: 30],
[name: \'Bob\', age: 40]
]
def flattenedList = listOfMaps.flatten()
println flattenedList
Output:
[John, 25, Jane, 30, Bob, 40]
In this example, the flatten() method is called on the listOfMaps variable, which results in a flattened list of values from the maps.
原文地址: https://www.cveoy.top/t/topic/qAGj 著作权归作者所有。请勿转载和采集!