【发布时间】:2010-09-15 01:45:02
【问题描述】:
有没有办法获取一张地图的键并用它的值替换另一张地图的值?
def wild = [animal1:"pet3", animal2:"dog", animal3:"pig"]
def pet = [pet1:"hamster", pet2:"fish", pet3:"cat"]
if(pet.containsKey(wild.animal1)) {
//replace wild.animal1 with the value contained in pet3 for example
//so wild.animal1 would equal "cat"
} else {
//dont change value
}
所以基本上我想知道我是否能够根据地图中的值找到一个键,并将该值替换为地图宠物中键的值。
有没有简单的方法来解决这个问题?
【问题讨论】: