Java , Removing object from ArrayList

前端 未结 4 491
独厮守ぢ
独厮守ぢ 2021-01-16 23:02

I have ClassA which has a static ArrayList of Objects

public static ArrayList meteorits = new ArrayList();

4条回答
  •  长情又很酷
    2021-01-16 23:38

    Iterator itr = yourlist.iterator();
    
    // remove all even numbers
    while (itr.hasNext()) {
           itr.remove();
    }
    

    this must work for you, other way to work around this issue is to use CopyOnWriteArrayList hopefully it help.

提交回复
热议问题