Java Lambda stream into different collections
<p>I have a Java lambda stream that parses a file and stores the results into a collection, based on some basic filtering.</p>

<p>I'm just learning lambdas so bear with me here if this is ridiculously bad.  But please feel free to point out my mistakes.</p>

<p>For a given file:</p>

<pre><code>#ignored
this
is
#ignored
working
fine
</code></pre>

<p>The code:</p>

<pre><code>List&lt;String&gt; matches;

Stream&lt;String&gt; g = Files.lines(Paths.get(givenFile));

matches = g.filter(line -&gt; !line.startsWith("#"))
           .collect(Collectors.toList());

["this", "is", "working", "fine"]
</code></pre>

<p>Now, how would I go about collecting the ignored lines into a second list within this same stream?  Something like:</p>

<pre><code>List&lt;String&gt; matches;
List&lt;String&gt; ignored; // to store lines that start with #

Stream&lt;String&gt; g = Files.lines(Paths.get(exclusionFile.toURI()));

matches = g.filter(line -&gt; !line.startsWith("#"))
           // how can I add a condition to throw these
           // non-matching lines into the ignored collection?
           .collect(Collectors.toList());
</code></pre>

<p>I realize it would be pretty trivial to open a new stream, alter the logic a bit, and .collect() the ignored lines easily enough.  But I don't want to have to loop through this file twice if I can do it all in one stream.</p>