Deleting objects from an ArrayList in Java

前端 未结 13 1956
轮回少年
轮回少年 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条回答
  •  离开以前
    2020-12-15 04:07

    First, I'd make sure that this really is a performance bottleneck, otherwise I'd go with the solution that is cleanest and most expressive.

    If it IS a performance bottleneck, just try the different strategies and see what's the quickest. My bet is on creating a new ArrayList and puting the desired objects in that one, discarding the old ArrayList.

提交回复
热议问题