Convert Map of maps into Lists using Java 8 Streams
<p>I have a map:</p>

<pre><code>Map&lt;String, Map&lt;Integer, List&lt;Integer&gt;&gt;&gt;
e.g. Map&lt;Name, Map&lt;Id, List&lt;ReferenceId&gt;&gt;&gt;

Outcome:
List&lt;Id&gt;
List&lt;ReferenceId&gt;
</code></pre>

<p>I wanna convert this map into two list of Integers. One list contains inner-map keys, and other contains inner-map value (i.e. <code>List&lt;Integer&gt;</code>)</p>

<p>Can anyone tell me how to do this in Java 8 using streams?    </p>

<p>I tried this way but got Cast Exception, can not convert String to Integer.</p>

<pre><code>map.values().stream()
    .map(m -&gt; m.entrySet()
    .stream()
    .map(e -&gt; e.getKey())
    .collect(Collectors.toList()))
    .flatMap(l -&gt; l.stream())
    .collect(Collectors.toList());
</code></pre>