Is there an accepted best practice in Java for deleting a list element while iterating over the list?

后端 未结 5 1295
执笔经年
执笔经年 2021-01-21 07:15

I\'m finding conflicting advice over the best way to avoid a ConcurrentModificationException while doing this:

    List Apples = appleC         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-21 08:02

    Since Java 8 you can now do this: apples.removeIf(apple -> apple.equals(this))

提交回复
热议问题