你可以这样做:
def map = [email:['hus@gmail.com', 'vin@gmail.com'], jobTitle:['SE', 'SD'], isLaptopRequired:['on', 'on'], phone:['9908899876', '7765666543'], name:['hus', 'Vin']]
def result = [:]
map.name.eachWithIndex { name, idx ->
result << [ (name): map.values()*.getAt( idx ) - name ]
}
assert result == [hus:['hus@gmail.com', 'SE', 'on', '9908899876'], Vin:['vin@gmail.com', 'SD', 'on', '7765666543']]
或者,您也可以这样做:
def result = [map.name,map.findAll { it.key != 'name' }.values().toList().transpose()].transpose().collectEntries()
但这只是以牺牲可读性和资源使用为代价的更少代码;-)