title: How is takeWhile different from filter?
body: <p>How is takeWhile() different from filter() in Java 9. What extra utility does it have?</p>
  
  <pre><code>Stream.of(1,2,3,4,5,6,7,8,9,10).filter(i -&gt; i &lt; 4 )
          .forEach(System.out::println);
  </code></pre>
  
  <p>This is perhaps what following would do</p>
  
  <pre><code>Stream.of(1,2,3,4,5,6,7,8,9,10).takeWhile(i -&gt; i &lt; 4 )
          .forEach(System.out::println);
  </code></pre>
  
  <p>What was the need of this new function then?</p>