title: Java 8 stream API: Exceptions when modifying Lists
body: <p>Let's take an <code>ArrayList</code> and fill it with with something simple:</p>
  
  <pre><code>List&lt;String&gt; list = new ArrayList&lt;&gt;();
  for (int i = 0; i &lt; 10; i++) {
      list.add(""+i);
  }
  </code></pre>
  
  <p>I will try to remove one member, say named 5, with a different ways of stream API. For this I define the method, that will give me a <code>ConcurentModificationException</code> when using traditional iteration with iterator.</p>
  
  <pre><code>void removeMember(String clientListener) {
      list.remove(clientListener);
  }
  </code></pre>
  
  <p>This code gives me that exception, which I understand:</p>
  
  <pre><code>list.parallelStream()
      .filter(string -&gt; string.equalsIgnoreCase("5"))
      .forEach(string -&gt; removeMember(string));
  </code></pre>
  
  <p>However, trying just <code>stream()</code>, not <code>parallelStream()</code> gives an null pointer exception (NPE), which is strange for me:</p>
  
  <pre><code>list.stream()
      .filter(string -&gt; string.equalsIgnoreCase("5"))
      .forEach(string -&gt; removeMember(string));
  </code></pre>
  
  <p>Now change the <code>List</code> type to <code>LinkedList&lt;&gt;</code>. Last code with <code>stream()</code> gives me a <code>ConcurentModificationException</code>, and <code>parallelStream()</code> suddenly works!</p>
  
  <p>So, the questions.</p>
  
  <ol>
  <li><p>Is the internal <code>parallelStream()</code> kitchen (Spliterators and other magic) smart enough to use such element removal for <code>LinkedList</code>? Will it always work?</p></li>
  <li><p>Why was that NPE for <code>ArrayList</code>? Why NPE, not <code>ConcurentModificationException</code> I mean.</p></li>
  </ol>