Thursday, 17 January 2019

Groovy: Spread map elements


Using '*:map' notation, we can spread the map elements.

HelloWorld.groovy

def africaCountries = ["Angola" : "Luanda", "Egypt" : "Cairo"]
def asiaCountries = ["India" : "new Delhi", "China" : "Beijing"]

def allCountries = ["Germany" : "Berlin", *:africaCountries, *:asiaCountries]

print allCountries

Output
[Germany:Berlin, Angola:Luanda, Egypt:Cairo, India:new Delhi, China:Beijing]

Previous                                                 Next                                                 Home

No comments:

Post a Comment