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.
Now I’m trying to iterate through this arraylist, call this method isExploded and remove the element from the list if it returns true.
I know how to iterate:
for (Iterator i = bombGrid.listIterator(); i.hasNext();) {
if () {
i.remove();
}
But I’ve no idea how to access the method isExploded of the Bomb class itself via the iterator. Does anyone know the answer to this?
Sincerely,
Luxo
You’ll need to get the Bomb using next :
Or if you can get an
Iterator<Bomb>from your bombGrid (is it anArrayList<Bomb>?):This supposes your iterator supports
remove, which is the case for example by the one given by anArrayList.