Doo*_*nob 38
只需使用传统的for循环:
for (int i = 0; i < yourArrayList.size(); i ++) {
// i is the index
// yourArrayList.get(i) is the element
}
Run Code Online (Sandbox Code Playgroud)
Zak*_*Zak 10
窃取门把手答案,但做出改变,否则会像海盗一样让我疯狂:
int arraySize = yourArrayList.size();
for (int i = 0; i < arraySize; i ++) {
// i is the index
// yourArrayList.get(i) is the element
}
Run Code Online (Sandbox Code Playgroud)
或者
int currentPosition = 0;
for (myItemType myItem :myArrayList) {
// do stuff
currentPosition++;
}
Run Code Online (Sandbox Code Playgroud)
您可以使用它list.indexOf(objectYouWantToFind);
来获取索引,如果它在容器中,您将收到其他-1
结果.
归档时间: |
|
查看次数: |
64445 次 |
最近记录: |