 <pre><code>IntStream.range(0, nodeNum) .mapToObj(ind -&gt; Stream.concat( getNeighbors(ind).stream(), getInNeighbors(ind).stream()) .collect(summingInt(Integer::intValue))) .collect(toList()); </code></pre>