Streaming two lists into a map
<p>I'm trying to learn java 8 streams and i'm having trouble converting the following code into streams</p>

<pre><code>parents = new ArrayList&lt;Integer&gt;() ...
children = new ArrayList&lt;Intger&gt;() ...
Map&lt;Integer, List&lt;Integer&gt;&gt; result = new HashMap&lt;Integer, List&lt;Integer&gt;&gt;();
for (Integer parentId : parents) {
    result.put(parentId, new ArrayList&lt;Integer&gt;(children));
}
return result;
</code></pre>

<p>Something like this doesn't work</p>

<pre><code>return parents.stream()
              .collect(toMap(p -&gt; p, children));
</code></pre>

<p>Tunaki provided the link that lead to the answer: <a href="https://stackoverflow.com/questions/36356041/how-to-create-a-map-with-java-stream-api-using-a-value-outside-the-stream">How to create a map with Java stream API using a value outside the stream?</a></p>

<p>The answer: </p>

<pre><code>return parents.stream()
              .collect(toMap(Function.identity(), e -&gt; new ArrayList&lt;&gt;(children)));
</code></pre>

<p>The problem was that I needed to pass an element to the value function, even if I don't use it and capture from outside instead. I was trying to give it a function that accepted nothing.</p>