Using Maps in Groovy is much simpler than in Java. Some key differences are: Map declaration and instantiation are simpler Elements of a Map can be accessed either using the bean style or array style Iterating across Maps is far less verbose in Groovy than in Java The code sample below is self explanatory //Declaring and instantiating a Map def emptyMap = [:] //Populating a Map //Notice that the keys which are strings are not //enclosed within quotes def population = [Estonia:1299371, Finland:5250275, Honduras:7792854, HongKong:7055071] //Non string keys must be enclosed in () def numbers = [(Integer.valueOf("1")):"One", (Integer.valueOf("2")):"Two"] //Accessing Map elements //Maps can be accessed using bean style and //array style notations respectively println "Estonia population: " + population.Estonia println "Finland population: " + populatio...
Write Awesome User Manuals and Tutorials for Software Products