class Sample {
def names = ["anna", "annie", "tommy", "bobby", "doggy"];
public static void main(def args) {
//Loop
for (i in 0..5) {
println "Hello, World!"
}
//Closure
def sample = new Sample();
//Operation of array
sample.names << "Terry";
println sample.names;
println "-------"
//lambda expression each
sample.names.each({ e -> println(e) });
println "-------"
//keyword it.
sample.names.each { println it }
println "-------"
//filter
List<String> matched = sample.names.findAll { e -> e.contains("o") }
matched.each { println it }
println "-------"
//sort
sample.names << "William";
sample.names << "bob";
List<String> sorted = sample.names.sort({ e -> e.length() })
sorted.each { println it }
println "-------"
//grouped
Map<Boolean, String> grouped = sample.names.groupBy { e -> e.contains("o") }
grouped.each { key, value -> println "$key:$value" }
}
}