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", id:1234] def x = mymap.find{ it.key == "likes" }?.value if(x) println "x value: ${x}" println x.getClass().name
?. checks for null and does not create an exception in Groovy. If the key does not exist, the result will be a org.codehaus.groovy.runtime.NullObject.
?.
org.codehaus.groovy.runtime.NullObject