title: Java 8 how to filter to two different lists?
body: <p>I have code looking something like this</p>
  
  <pre><code>List&lt;MyObj&gt; objs = ... // &lt;- lot of objs
  
  List&lt;MyObj&gt; objsThatAreA = new ArrayList&lt;&gt;();
  List&lt;MyObj&gt; objsThatAreB = new ArrayList&lt;&gt;();
  
  for (MyObj obj : objs) {
      if (isA(obj)){
          objsThatAreA .add(obj);
      } else if isB(obj))
          objsThatAreB.add(obj);
      }
      // Others are "discarded" Can be C,D,E and so on, but all are exclusive, can only be in one state. 
  }
  </code></pre>
  
  <p>I would want to refactor into something like this</p>
  
  <pre><code>// Can this be done O(n)?
  Stream&lt;MyObj&gt; objStream  = objs.stream();
  Stream&lt;MyObj&gt; objsThatAreA = objStream.filter(o -&gt; isA(i));
  Stream&lt;MyObj&gt; objsThatAreB = objStream.filter(o -&gt; isB(i));
  </code></pre>
  
  <p>My question is, in the second much more readable example, I iterate objs twice. Is there some way to achieve the same result in one pass using streams?</p>
  
  <p>Key question is if it is possible to keep it O(n) and not O(2n) or O(cN) where c are all possible states (~14)</p>