how to print the index number of elements in the ArrayList using for each looping

前端 未结 4 2009
一整个雨季
一整个雨季 2021-01-22 11:36

Can anybody tell me how to print the index number of elements in the ArrayList using for each looping in Java.

4条回答
  •  太阳男子
    2021-01-22 11:56

    You have to keep track of the index numbers yourself, as you loop through the ArrayList. The List iterator won't do that for you.

    You'd normally do that through a separate variable. You could store objects with an associated index, but you'd have to be sure to maintain ordering (by not deleting, resorting etc.)

提交回复
热议问题