Aimad MAJDOU Aimad MAJDOU - 2 years ago 69
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.

Answer Source

Just use a traditional for loop:

for (int i = 0; i < yourArrayList.size(); i ++) {
    // i is the index
    // yourArrayList.get(i) is the element
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download