This approach also enables the enhanced for loop to walk through the children.
这种方法还使得for循环可以遍历所有孩子。
To summarize: use the enhanced for loop by default, but consider a hand-written counted loop for performance-critical ArrayList iteration.
结论:优先采用改进for循环,但在性能要求苛刻的ArrayList迭代中,考虑采用手写计数循环。
The enhanced for loop (also sometimes known as "for-each" loop) can be used for collections that implement the Iterable interface and for arrays.
改进for循环(有时被称为“for - each”循环)能够用于实现了iterable接口的集合类及数组中。
The enhanced for loop, sometimes called the for-each loop, is translated by the compiler as if the programmer had supplied the equivalent old-style for loop.
增强的for循环有时叫做for - each循环,编译器编译它的时候,情形与程序员提供旧式for循环一样。
Some of the most interesting changes, such as the enhanced for loop, are basically just syntax changes that provide a shortcut for expressing a programming operation.
一些最有趣的更改,比如增强的for循环,基本上只是语法更改,即为表示编程操作提供快捷方式。
The main method USES an enhanced for loop to iterate through the different primitives and a simple switch statement on the current instance to set the size value of each primitive.
main方法使用增强的for循环来迭代通过不同的原语,并在当前实例上使用一个简单的switch语句来设置每个原语的大小值。
Note that I used an old-fashioned explicit int loop, rather than the more convenient for (int i : integers) enhanced for loop, because it is slightly faster, even for arrays (see Resources).
注意,我使用的是一个老式的显式int循环,而不是更方便的for (inti :integers) 改进型 for 循环,因为它的速度快一点儿(参见 参考资料)。
Most of the time, we just slap Iterator inside a for() loop or enhanced for() loop and move on, so to speak.
可以这么说,大部分时间我们只是将Iterator 随意放到for()循环或加强 for() 循环中,然后就继续其他操作了。
Most of the time, we just slap Iterator inside a for() loop or enhanced for() loop and move on, so to speak.
可以这么说,大部分时间我们只是将Iterator 随意放到for()循环或加强 for() 循环中,然后就继续其他操作了。
应用推荐