Created
August 25, 2013 10:28
-
-
Save peysal/6333149 to your computer and use it in GitHub Desktop.
Revisions
-
peysal created this gist
Aug 25, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ def emptyMap = [:] assert emptyMap.size() == 0 def notEmptyMap = ["person1":"john", "person2":"mus"] assert notEmptyMap.size() == 2 notEmptyMap.put "person3","test" //adding to existing one assert notEmptyMap.size() == 3 notEmptyMap["person4"] = "beth" assert notEmptyMap.size() == 4 assert notEmptyMap.get("person1") == "john" //accessing the value assert notEmptyMap.person1 == "john" assert notEmptyMap["person1"] == "john" notEmptyMap.each{ k,v -> println "key=${k}: value=${v}"} //iterating notEmptyMap.each{ it -> println "key=${it.key}:value${it.value}"} def toBeRemove = ["person3" :"oh","person4":"la"] assert toBeRemove.each{it -> notEmptyMap.remove(it.key) }.size() == 2 notEmptyMap += toBeRemove //concat assert notEmptyMap.size() == 4