Deleting objects from an ArrayList in Java

前端 未结 13 1974
轮回少年
轮回少年 2020-12-15 03:14

I need to delete some objects from an ArrayList if they meet a condition and I\'m wondering which way could be more efficient.

Here\'s the situation: I

13条回答
  •  Happy的楠姐
    2020-12-15 04:09

    You could iterate backwards and remove as you go through the ArrayList. This has the advantage of subsequent elements not needing to shift and is easier to program than moving forwards.

提交回复
热议问题