def movieList = ['Dersu Uzala', 'Ran', 'Seven Samurai'] // Looks like an array, but is a list
assert movieList[2] == 'Seven Samurai'
movieList[3] = 'Casablanca' // Adds an element to the list
assert movieList.size() == 4
def monthMap = [ 'January' : 31, 'February' : 28, 'March' : 31 ] // Declares a map
assert monthMap['March'] == 31 // Accesses an entry
monthMap['April'] = 30 // Adds an entry to the map
assert monthMap.size() == 4
class Example {
static void main(String[] args) {
def lst = [11, 12, 13, 14];
lst.each {println it}
}
}
class Example {
static void main(String[] args) {
def mp = ["TopicName" : "Maps", "TopicDescription" : "Methods in Maps"]
mp.each {println it}
mp.each {println "${it.key} maps to: ${it.value}"}
}
}
class Example {
static void main(String[] args) {
def lst = [1,2,3,4];
lst.each {println it}
println("The list will only display those numbers which are divisible by 2")
lst.each{num -> if(num % 2 == 0) println num}
}
}
No comments:
Post a Comment