「Groovy」for in文でリストの要素を取得するサンプル

2021年8月31日

書式
for(変数名 in リスト名)
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
class Arkxample {
static void main(String[] args) {
// def リストの宣言
def cftLst = [11, 22, 'study', new Date(),'arkgame']
println("for in文でリストをループする")
for(item in cftLst){
println(item)
}
}
}
class Arkxample { static void main(String[] args) { // def リストの宣言 def cftLst = [11, 22, 'study', new Date(),'arkgame'] println("for in文でリストをループする") for(item in cftLst){ println(item) } } }
class Arkxample { 
   static void main(String[] args) { 
      // def リストの宣言
      def cftLst = [11, 22, 'study', new Date(),'arkgame']
      
      println("for in文でリストをループする")
      for(item in cftLst){
        println(item)
      } 
   } 
}

実行結果
for in文でリストをループする
11
22
study
Tue Aug 31 20:14:07 JST 2021
arkgame

Groovy

Posted by arkgame