First Groovy
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 //Closure 11 def sample = new Sample(); 12 //Operation of array 13 sample.names << "Terry"; 14 println sample.names; 15 16 println "-------" 17 //lambda expression each 18 sample.names.each({ e -> println(e) }); 19 20 println "-------" 21 //keyword it. 22 sample.names.each { println it } 23 24 println "-------" 25 26 //filter 27 List<String> matched = sample.names.findAll { e -> e.contains("o") } 28 matched.each { println it } 29 30 println "-------" 31 //sort 32 sample.names << "William"; 33 sample.names << "bob"; 34 List<String> sorted = sample.names.sort({ e -> e.length() }) 35 sorted.each { println it } 36 37 println "-------" 38 //grouped 39 Map<Boolean, String> grouped = sample.names.groupBy { e -> e.contains("o") } 40 grouped.each { key, value -> println "$key:$value" } 41 } 42 }
-----------------------------------------------------------------
现为独立咨询师。为软件企业或者其他企业的软件采购部门提供咨询,帮助改进软件开发流程,员工技术能力提升,以帮助企业在质量成本交货期三方面得到改善。