There are two ways to get the elements of a map.
a.
Using get method
b.
Using subscript operator.
HelloWorld.groovy
def countryCapitals = ["India" : "new Delhi", "Australia" : "Canberra"] countryCapitals.put("Bulgaria", "Sofia") countryCapitals["Canada"] = "Ottawa" println "Capital of Bulgaria is ${countryCapitals.get('Bulgaria')}" println "Capital of India ${countryCapitals['India']}"
Output
Capital of Bulgaria is Sofia
Capital of India new Delhi
No comments:
Post a Comment