title: Why iterator.forEachRemaining doesnt remove element in the Consumer lambda?
body: <p>Lets have a look at this example:</p>
  
  <pre><code>public class ListIteratorTest {
      public static void main(String[] args) {
          List&lt;String&gt; list = new ArrayList&lt;&gt;();
          list.add("element1");
          list.add("element2");
          list.add("element3");
          list.add("element4");
  
          ListIterator&lt;String&gt; iterator = list.listIterator();
      }
  }
  </code></pre>
  
  <p>And now, this works fine:</p>
  
  <pre><code>    // prints elements out, and then appropriately removes one after another
      while (iterator.hasNext()){
          System.out.println(iterator.next());
          iterator.remove();
      }
  </code></pre>
  
  <p>while this throws an IllegalStateException:</p>
  
  <pre><code>        // throws IllegalStateException, why?
          iterator.forEachRemaining(n -&gt; {
              System.out.println(n);
              iterator.remove();
          });
  </code></pre>
  
  <p>My question is short: why? </p>