gpt4 book ai didi

java - for() 函数中的 ":"

转载 作者:搜寻专家 更新时间:2023-11-01 01:02:19 27 4
gpt4 key购买 nike

我正在做一项涉及董事会的作业。基本代码给了我们修改,但是我不明白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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com