title: Using an iterator with an enhanced for loop in Java?
body: <p>Okay so in my project for class I'm looking through an ArrayList of my class "Sprite" with an enhanced for loop, and I occasionally need to delete the Sprite that I'm looking at. I'm told I can do this safely (i.e. not deleting the Sprite I'm currently looking at) with Iterators. I looked it up on Oracle's java documentation but I don't really understand it.. </p>
  
  <p>Here's my method:</p>
  
  <pre><code>public void forward() {
      for (Sprite s : sprites) {
          s.move();
          for(Sprite x : sprites){
              if(s!=x &amp;&amp; s.overlaps(x)){                  
                  if(s instanceof Razorback &amp;&amp; x instanceof Opponent){
                      x.hit();
                  }
                  if(x instanceof Razorback &amp;&amp; s instanceof Opponent){
                      s.hit();
                  }
              }
  
          }
          if(s.shouldRemove())
              sprites.remove(s);
  
      }
  
  }
  </code></pre>
  
  <p>if(s.shouldRemove()) is where I need to implement an iterator. If shouldRemove() return true, s needs to be removed from the ArrayList.</p>