2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

how to iterate map in groovy

how to iterate map in groovy

basically i have map as below:

def studentMap = ["class1":"student1", "class2":"student2"]

i am not sure how to iterate this using groovy code.

userimage
To iterate this try as below:

def studentMap = ['class1':'student1', 'class2':'student2']
studentMap.each { class, student ->
    println "${class} has student named ${student}"
};
Answer is