Groovy

Summary

  • 基本循环结构。
  • 传统的for循环结构。
  • 使用 for in 模式的循环结构。

Demo

class Main {
    static void main(args){
        String str = ""

        // 第一种,传统的循环
        for(int i=0; i<5; i++){
            str += "Groovy"
        }


        // 第二种,for in 的遍历循环,可对应多种数据类型。
        ArrayList<String> arrayList = new ArrayList<String>()
        arrayList.addAll(["A","B","C"])
        for (x in arrayList){
            println(x)
        }

    }
}
原文地址:https://www.cnblogs.com/duchaoqun/p/12978341.html