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

前端 未结 7 885
耶瑟儿~
耶瑟儿~ 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:13

    It's a for each loop. You could also write it like this:

    for(int i = 0; i < successors.size(); i++) {
        Node son = successors.get(i);
    }
    

    Though the only time I'd personally do that is when the index is needed for doing something other than accessing the element.

提交回复
热议问题