groovy: safely find a key in a map and return its value
问题 I want to find a specific key in a given map. If the key is found, I then want to get the value of that key from the map. This is what I managed so far: def mymap = [name:"Gromit", likes:"cheese", id:1234] def x = mymap.find{ it.key == "likes" } if(x) println x.value This works, the output is "cheese" as expected. Great, but I don't want to do x.value at the end, and I don't want to do if(x) . I want x to directly contain the value somehow. I can't get the value directly into x like this: def