Java delete arraylist iterator

后端 未结 3 586
借酒劲吻你
借酒劲吻你 2020-12-20 00:22

I\'ve an ArrayList in Java of my class \'Bomb\'.

This class has a method \'isExploded\', this method will return true if the bomb has been exploded, else false.

3条回答
  •  轮回少年
    2020-12-20 01:14

    If you use Java 5, use generics:

    List bombGrid = ...;
    for (Iterator i = bombGrid.iterator(); i.hasNext();) {
      if (i.next().isExploded()) {         
        i.remove();
      }
    }
    

提交回复
热议问题