zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    UITabar 设置字体大小/颜色
    NSURLSession的基本使用
    报错/警告提示
    实现毛玻璃模糊效果/DRNRealTimeBlur
    免证书真机调试
    xcode添加音效
    NSCalenda日历类
    NSDate--日期格式
    NSArray其中的方法--遍历,
    Mysql学习笔记004
  • 原文地址:https://www.cnblogs.com/stephen-wang/p/3388161.html
Copyright © 2011-2022 走看看