How can I access the previous/next element in an ArrayList?

后端 未结 5 558

I iterate through an ArrayList this way:

for (T t : list){
  ...
}

When I did this, I never thought I had to access the previous and next eleme

5条回答
  •  有刺的猬
    2021-02-04 08:59

    I think I found the solution it is simple in fact, but I cannot delete this post already because it has answers..

    I just added T t = list.get(i); in the second for-loop, all other code remains unchanged.

提交回复
热议问题