Aimad MAJDOU Aimad MAJDOU - 1 year ago 29
Java Question

Get the current index of a for each loop iterating an ArrayList

I'm iterating an

using the for each loop, but I don't know how to get the current index where the loop is.

I did Google it, but I couldn't find anything helpful.

Please, if someone could tell me how to get the current index, I'll be grateful.


Just use a traditional for loop:

for (int i = 0; i < yourArrayList.size(); i ++) {
    // i is the index
    // yourArrayList.get(i) is the element