groovy: safely find a key in a map and return its value
The whole point of using Maps is direct access. If you know for sure that the value in a map will never be Groovy-false, then you can do this: def mymap = [name:”Gromit”, likes:”cheese”, id:1234] def key = “likes” if(mymap[key]) { println mymap[key] } However, if the value could potentially be Groovy-false, you should use: … Read more