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

后端 未结 5 583

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 09:02

    I found a solution too. It was next.

    For next: letters.get(letters.indexOf(')')+1)

    For previous: letters.get(letters.indexOf(')')-1)

提交回复
热议问题