title: Map entity structure to map of maps using streams
body: <p>I have the entities:</p>
  
  <pre><code>public class Library {
    String name;
    Set&lt;Book&gt; books;
  }
  
  public class Book {
    String isbn;
    String title;
  }
  </code></pre>
  
  <p>Now I need a</p>
  
  <pre><code>Map&lt;String, Map&lt;String, Book&gt;&gt; mapByLibraryNameAndIsbn;
  </code></pre>
  
  <p>where the key of the first <code>Map</code> is the name of the <code>Library</code> and the key of the second <code>Map</code> the isbn of the <code>Book</code>.</p>
  
  <p>To do that, I want to use java streams and some collectors. I tried it with groupingBy and toMap, but with any success.</p>
  
  <p><strong>Update 1:</strong></p>
  
  <p>I tried so far</p>
  
  <pre><code>Map&lt;String, List&lt;Book&gt;&gt; libraryList.stream().collect(groupingBy(l -&gt; l.getName(), toList()));
  </code></pre>
  
  <p>but I just got a <code>Map</code> of <code>List</code>s.</p>
  
  <p>Any ideas? TIA!</p>