我想在完成后从ArrayList
中删除一个对象,但我找不到方法来执行此操作。试图删除它像下面的示例代码不想工作。我怎么能到这个循环中的当前对象px
的迭代器去除它?从ArrayList中为每个循环移除对象
for(Pixel px : pixel){
[...]
if(px.y > gHeigh){
pixel.remove(pixel.indexOf(px)); // here is the thing
pixel.remove(px); //doesn't work either
}
}
可能重复(http://stackoverflow.com/questions/1196586/calling-remove-in -foreach-loop-in-java) – DNA 2012-03-13 20:21:09
可能的重复[迭代通过集合,避免ConcurrentModificationException在循环中删除时](http://stackoverflow.com/questions/223918/iterating-through-a-collection-avoiding-concurrentmodificationexception -when-re) – omerhakanbilici 2016-10-31 14:16:10