groovy listmap拍平成map
要将一个Groovy List
def list = [
[name: 'John', age: 25],
[name: 'Mary', age: 30],
[name: 'David', age: 35]
]
def flattenedMap = list.collectEntries { map ->
map.collectEntries()
}
println flattenedMap
输出结果:
[name:John, age:25, name:Mary, age:30, name:David, age:35]
在上述代码中,我们使用collectEntries方法遍历每个Map,并将其键值对添加到新的Map(flattenedMap)中。最终,flattenedMap中包含了所有Map的键值对
原文地址: http://www.cveoy.top/t/topic/iUzA 著作权归作者所有。请勿转载和采集!