Removing object from ArrayList in for each loop

前端 未结 6 1386
[愿得一人]
[愿得一人] 2020-12-02 23:26

I would like to remove an object from an ArrayList when I\'m done with it, but I can\'t find way to do it. Trying to remove it like in the sample code below doe

6条回答
  •  囚心锁ツ
    2020-12-03 00:23

    you need to create and access the iterator explicitly

    Iterator it = pixel.iterator();
    while(it.hasNext()){
    Pixel.px = it.next();
    //...
    it.remove();
    }
    

提交回复
热议问题