title: java ArrayList remove object while iterating
body: <p>I'm running an iterator over an arraylist and am trying to remove an item when a condition is true.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>String item = (String) model.getElementAt(selectedIndices[i]);
  Iterator it = p.eggMoves.iterator();
  while(it.hasNext())
  {
      String text = (String) it.next();
      if ( text.equals(item) )
      {
          it.remove();
          p.eggMoves.remove(selectedIndices[i]);
          model.removeElementAt(selectedIndices[i]);
      }
  }
  </code></pre>
  
  <p>Now this code works fine, the item is removed from both the p object and the jlist, but it throws an "ConcurrentModificationException" exception at the it.next() line.</p>
  
  <p>How do I solve this?</p>