For loop in the form of : “for (A b : c)” in Java

前端 未结 7 897
耶瑟儿~
耶瑟儿~ 2021-01-13 12:32

This is the first time that I\'ve seen this kind of syntax :

// class Node
public class Node { 

...
...

}

public class Otherclass { ... }

Otherclass gra         


        
相关标签:
7条回答
  • 2021-01-13 13:31

    That is a for-each loop (also called an enhanced-for.)

    for (type var : arr) { //could be used to iterate over array/Collections class
        body-of-loop
    }
    

    The basic for loop was extended in Java 5 to make iteration over arrays and other collections more convenient. This newer for statement is called the enhanced for or for-each

    (Documentation)

    0 讨论(0)
提交回复
热议问题