title: How to separate a List by a condition using Java 8 streams
body: <p>Consider the following code:</p>
  
  <pre><code> List&lt;Integer&gt; odd = new ArrayList&lt;Integer&gt;();
   List&lt;Integer&gt; even = null;  
   List&lt;Integer&gt; myList = Arrays.asList(1,2,3,4,5,6,7,8,9,10);
   even = myList.stream()
                .filter(item -&gt; {
                     if(item%2 == 0) { return true;}
                     else { 
                             odd.add(item); 
                             return false;
                     }
                })
                .collect(Collectors.toList());
  </code></pre>
  
  <p>What I am trying to do here is get the even and odd values from a list into separate lists. </p>
  
  <p>The stream <code>filter()</code> method returns <code>true</code> for even items and the stream collector will collect them.<br>
  For the odd case, the filter will return <code>false</code> and the item will never reach the collector. </p>
  
  <p>So I am adding such odd numbers in another list I created before under the <code>else</code> block. </p>
  
  <p>I know this is not an elegant way of working with streams. For example if I use a parallel stream then there will be thread safety issue with the odd list. I cannot run it multiple times with different filters because of performance reasons (should be O(n)).</p>
  
  <p>This is just an example for one use-case, the list could contain any object and the lambda inside the filter needs to separate them based on some logic into separate lists. </p>
  
  <p>In simple terms: from a list create multiple lists containing items separated based on some criteria. </p>
  
  <p>Without streams it would be just to run a for loop and do simple if-else and collect the items based on the conditions. </p>