Constructing list from multi level map in Java 8 : <p>I have a multi-level map as follows:</p>

<pre><code> Map&lt;String, Map&lt;String, Student&gt; outerMap = 
    {"cls1" : {"xyz" : Student(rollNumber=1, name="test1")}, 
     "cls2" : {"abc" : Student(rollNumber=2, name="test2")}}
</code></pre>

<p>Now I want to construct a list of string from the above map as follows:</p>

<pre><code>["In class cls1 xyz with roll number 1",
 "In class cls2 abc with roll number 2"] 
</code></pre>

<p>I have written as follows, but this is not working, in this context I have gone through the post as well: <a href="https://stackoverflow.com/questions/51818929/java-8-streams-nested-maps-to-list">Java 8 Streams - Nested Maps to List</a>, but did not get much idea. </p>

<pre><code> List&lt;String&gt; classes = outerMap.keySet();
 List&lt;String&gt; studentList = classes.stream()
      .map(cls -&gt; 
           outerMap.get(cls).keySet().stream()
           .map(student -&gt; "In class "+ cls +
            student + " with roll number " +
            outerMap.get(cls).get(student).getRollNum() +"\n"
            ).collect(Collectors.toList());
</code></pre>
