title: How to remove element from list that is being iterated in another method?
body: <p>I have a class member list I am iterating over in following method:</p>
  
  <pre><code>public void deselectAll() {
      Iterator&lt;GraphicalObject&gt; iterator = selectedObjects.iterator();
      while(iterator.hasNext())
      {
          iterator.next().setSelected(false);
      }
  }
  </code></pre>
  
  <p>Method setSelected() will cause current element to be removed in subsequent calls that setSelected() triggers. 
  Is there a way I can remove current element somewhere out of this method and continue iterating normally?</p>
  
  <p><strong>EDIT</strong>: I see question is ambiguous a bit. Here's example showing problem in context ( I left out irrelevant code):
  <pre>
  public class Model {</p>
  
  <pre><code>     private List&lt;GraphicalObject&gt; selectedObjects;
  
       private final GraphicalObjectListener listener = new GraphicalObjectListener() {
             @Override
             public void graphicalObjectSelectionChanged(GraphicalObject go) {
                  int index = selectedObjects.indexOf(go);
                  if(go.isSelected()) {
                       if(index == -1) {
                            selectedObjects.add(go);
                        } else {
                            return;
                        }
                  } else {
                        if(index != -1) {
                            selectedObjects.remove(index);
                        } else {
                            return;
                        }
                  }
                  notifyListeners();
            }
      };
  
      public void deselectAll() {
          Iterator&lt;GraphicalObject&gt; iterator = selectedObjects.iterator();
          while(iterator.hasNext()){
                  iterator.next().setSelected(false);
          }
      } 
  </code></pre>
  
  <p>}</p>
  
  <p>public abstract class AbstractGraphicalObject implements GraphicalObject {</p>
  
  <code>    @Override
      public void setSelected(boolean selected) {
          this.selected = selected;
          notifySelectionListeners();
      }
  
      public void notifySelectionListeners() {
          for (GraphicalObjectListener listener : listeners) {
              listener.graphicalObjectSelectionChanged(this);
          }
      }
  </code></pre>
  
  <p>}</p>