title: Java 8 List<Foo> to Map<String, Map<String, List<String>>>
body: <p>I have following class:</p>
  
  <pre><code>public class Foo {
      private String areaName;
      private String objectName;
      private String lineName;
  }
  </code></pre>
  
  <p>Now I want to convert a <code>List&lt;Foo&gt;</code> to <code>Map&lt;String, Map&lt;String, List&lt;String&gt;&gt;&gt;</code>. I found <a href="https://stackoverflow.com/a/33254512/7109162">this answer</a> which helped me develop following code:</p>
  
  <pre><code>Map&lt;String, Map&lt;String, List&lt;String&gt;&gt;&gt; testMap = foos.stream().collect(Collectors.groupingBy(e -&gt; e.getAreaName(),
          Collectors.groupingBy(e -&gt; e.getObjectName(), Collectors.collectingAndThen(Collectors.toList(),
                  e -&gt; e.stream().map(f -&gt; f.getLineName())))));
  </code></pre>
  
  <p>The only problem with this code is the part where it should convert to <code>List&lt;String&gt;</code>. I couldn't find a way to convert <code>Foo</code> to <code>List</code> in that part.</p>
  
  <p>Another approach which results in <code>Map&lt;String, Map&lt;String, List&lt;Foo&gt;&gt;&gt;</code>:</p>
  
  <pre><code>Map&lt;Object, Map&lt;Object, List&lt;Foo&gt;&gt;&gt; testMap = ventures.stream().collect(Collectors.groupingBy(e -&gt; e.getAreaName(),
          Collectors.groupingBy(e -&gt; e.getObjectName(), Collectors.toList())));
  </code></pre>
  
  <p><strong>What do I need to change in order to receive <code>Map&lt;String, Map&lt;String, List&lt;String&gt;&gt;&gt;</code> from <code>List&lt;Foo&gt;</code>?</strong></p>