title: Calling remove in foreach loop in Java
body: <p>In Java, is it legal to call remove on a collection when iterating through the collection using a foreach loop?  For instance:</p>
  
  <pre><code>List&lt;String&gt; names = ....
  for (String name : names) {
     // Do something
     names.remove(name).
  }
  </code></pre>
  
  <p>As an addendum, is it legal to remove items that have not been iterated over yet? For instance, </p>
  
  <pre><code>//Assume that the names list as duplicate entries
  List&lt;String&gt; names = ....
  for (String name : names) {
      // Do something
      while (names.remove(name));
  }
  </code></pre>