我正在做一项涉及董事会的作业。基本代码给了我们修改,但是我不明白for()的参数中的:
是什么意思。它是否遍历所有板(ArrayList
)?
private ArrayList<MovingElement> moveElems = new ArrayList<MovingElement>();
for (MovingElement mElement : moveElems) {
mElement.step();
}
最佳答案
这是 for
循环的一种特殊形式,用于遍历数组和任何 Iterable
,其中包括任何 Collection
.
这称为 for-each 循环,如:for each element of a list。
阅读:for (MovingElement mElement : moveElems)
as _for each MovingElement
in the collection moveElems_
.
参见:The For-Each Loop .
关于java - for() 函数中的 ":",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12734550/