如何将mylist作为keys和myanotherlist作为values添加到myMap
def mylist = [ John, Paul, Emily ]
def myanotherlist = [ 23, 45, 56 ]
def myMap = [:]
//
println "myMap: ${myMap}"
println "Age of Paul is: ${myMap['Paul']}"所需输出:
myMap: [
John : 23
Paul : 45
Emily : 56
]
Age of Paul is: 45发布于 2020-01-25 00:31:47
您可以对索引列表(从0到mylist.size())使用collectEntries:
def myMap = (0..<mylist.size()).collectEntries{[(mylist[it]) : myanotherlist[it]]}https://stackoverflow.com/questions/59900300
复制相似问题