Skip to content

Instantly share code, notes, and snippets.

@gwsu2008
Last active January 27, 2020 03:40
Show Gist options
  • Save gwsu2008/ffafc2d2dec3b746ad400c3f231201f8 to your computer and use it in GitHub Desktop.
Save gwsu2008/ffafc2d2dec3b746ad400c3f231201f8 to your computer and use it in GitHub Desktop.
Groovy_Tips
// Check if key exists in map
def mymap = [name:"Gromit", likes:"cheese", id:1234]
def key = "likes"
if(mymap[key]) {
println mymap[key]
}
if(mymap.containsKey(key)) {
println mymap[key]
}
def value = mymap[key] ?: "default"
def mymap = [name:"Gromit", likes:"cheese", id:1234]
def x1 = mymap.get('likes', '[nothing specified]')
println "x value: ${x}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment