title: Java 8 - Once Stream is consumed and operated giving error, but in another case its not
body: <p>I am new to Java 8 and looking to understand the difference between the two scenarios. I know that once a stream is operated and consumed then stream cant be reused again it will give an error.</p>
  
  <p><strong>Scenario-1:</strong></p>
  
  <pre><code>List&lt;String&gt; title = Arrays.asList("Java8", "In", "Action");
          Stream&lt;String&gt; s = title.stream();
          s.forEach(System.out::println);
          s.forEach(System.out::println); // THIS WILL GIVE ERROR - streams has been already operated and closed.
  </code></pre>
  
  <p>When I run this, I get below error... which is fair.</p>
  
  <pre><code>Java8
  In
  Action
  Exception in thread "main" java.lang.IllegalStateException: stream has already been operated upon or closed
      at java.util.stream.AbstractPipeline.sourceStageSpliterator(Unknown Source)
      at java.util.stream.ReferencePipeline$Head.forEach(Unknown Source)
      at com.test.Java8InAction.CH4.TraversableOnlyOnce.main(TraversableOnlyOnce.java:12)
  </code></pre>
  
  <p><strong>Scenario-2:</strong></p>
  
  <pre><code>// Filtering unique elements
  List&lt;Integer&gt; numbers = Arrays.asList(1, 2, 1, 3, 3, 2, 4);
  numbers.stream().forEach(System.out::println);
  numbers.stream().filter(n -&gt; n % 2 == 0).distinct().forEach(System.out::println);
  numbers.stream().filter(n -&gt; n % 2 == 0).forEach(System.out::println);
  </code></pre>
  
  <p>Here also I have operated stream and closed the terminal operation, then why I did not get any error?</p>