Last active
January 27, 2020 03:40
-
-
Save gwsu2008/ffafc2d2dec3b746ad400c3f231201f8 to your computer and use it in GitHub Desktop.
Groovy_Tips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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