1 class Sample { 2 def names = ["anna", "annie", "tommy", "bobby", "doggy"]; 3 4 public static void main(def args) { 5 //Loop 6 for (i in 0..5) { 7 println "Hello, World!" 8 } 9 10 //Closure11 def sample = new Sample();12 //Operation of array13 sample.names << "Terry";14 println sample.names;15 16 println "-------"17 //lambda expression each18 sample.names.each({ e -> println(e) });19 20 println "-------"21 //keyword it.22 sample.names.each { println it }23 24 println "-------"25 26 //filter27 Listmatched = sample.names.findAll { e -> e.contains("o") }28 matched.each { println it }29 30 println "-------"31 //sort32 sample.names << "William";33 sample.names << "bob";34 List sorted = sample.names.sort({ e -> e.length() })35 sorted.each { println it }36 37 println "-------"38 //grouped39 Map grouped = sample.names.groupBy { e -> e.contains("o") }40 grouped.each { key, value -> println "$key:$value" }41 }42 }