在Groovy中,可以使用flatten()方法将List<Map>拍平为一个单独的Map。具体实现如下:

def list = [
    [name: 'John', age: 30],
    [name: 'Jane', age: 25],
    [name: 'Bob', age: 35]
]

def flattenedMap = list.flatten().collectEntries { it }
println flattenedMap

输出结果:

[name:John, age:30, name:Jane, age:25, name:Bob, age:35]

在这个例子中,首先使用flatten()方法将List<Map>拍平为一个扁平的列表。然后使用collectEntries()方法将每个键值对转换为一个Map。最终,得到一个拍平后的Map对象flattenedMap

groovy listmap拍平成map flattenedMap

原文地址: http://www.cveoy.top/t/topic/iUBu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录