convert list of object into a map of <String,Map<String,Integer>> java8 streams
<p>hello I have a list of objects my object have three fields</p>

<pre><code>class MyObject{
   String x;
   String y;
   int  z;
   //getters n setters
}
</code></pre>

<p>I need to convert this list into a <code>Map&lt;String,Map&lt;String,Integer&gt;&gt;</code></p>

<p>that is like this:
<code>{x1:{y1:z1,y2:z2,y3:z3},x2{y4:z4,y5:z5}}</code> format I want to do this in Java 8 which I think I am relatively new to it.</p>

<p>I have tried the following :</p>

<pre><code>Map&lt;String,Map&lt;String,Integer&gt;&gt; map=list.stream().
                collect(Collectors.
                        groupingBy(MyObject::getX,list.stream().
                                collect(Collectors.groupingBy(MyObject::getY,
                                        Collectors.summingInt(MyObject::getZ)))));
</code></pre>

<p>this does not even compile. help is much appreciated</p>