title: From a stream operation, how do I map a set of values to anoter value?
body: <p>This is a modified Person class named <code>CavePerson</code>. It has no getters, but does have variables that correspond to indexes in a CSV/Excel file. Each <code>CavePerson</code> has a number, name, gender, and the year they were introduced in.</p>
  <pre class="lang-java prettyprint-override"><code>public class CavePerson {
     public final int num;
     public final String name;
     public final String gender;
     public final int intro_year;
  
     public CavePerson (int aNum, String aName, String aGender, int anIntro_year){
        this.num = aNum;
        this.name = aName;
        this.gender = aGender;
        this.intro_year = anIntro_year;
     }
  
     public static CavePerson lineValues(String line) {
        String array = line.split(&quot;,&quot;);
        int numA = array[0];
        String nameA = array[1];
        String genderA array[2];
        int intro_yearA = array[3];
        return new CavePerson(numA, nameA, genderA, intro_yearA);
     }
  }
  </code></pre>
  <p>Each line in this <code>cavepeople.csv</code> file is a <code>CavePerson</code> object:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Num</th>
  <th>Name</th>
  <th>Gender</th>
  <th>Year</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>Fred</td>
  <td>Male</td>
  <td>1960</td>
  </tr>
  <tr>
  <td>2</td>
  <td>Wilma</td>
  <td>Female</td>
  <td>1960</td>
  </tr>
  <tr>
  <td>3</td>
  <td>Barney</td>
  <td>Male</td>
  <td>1961</td>
  </tr>
  <tr>
  <td>4</td>
  <td>Betty</td>
  <td>Female</td>
  <td>1961</td>
  </tr>
  <tr>
  <td>5</td>
  <td>Dino</td>
  <td>Male</td>
  <td>1964</td>
  </tr>
  <tr>
  <td>6</td>
  <td>BamBam</td>
  <td>Male</td>
  <td>1966</td>
  </tr>
  <tr>
  <td>7</td>
  <td>Puss</td>
  <td>Male</td>
  <td>1967</td>
  </tr>
  <tr>
  <td>8</td>
  <td>Pebbles</td>
  <td>Female</td>
  <td>1966</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I am practicing streams, and I wanted to get a count of each gender that was introduced by each year. The expected result return a map of each year and list the number of male/female characters that were introduced that year. It should look like this:</p>
  <p><code>1960, Male 1, Female 1</code></p>
  <p>This is what I have so far. From a <code>Stream</code>, I map each year to the count of each gendered character, but I am getting a type error stating that I cannot convert <code>Map&lt;Object,Long&gt;</code> to my desired <code>Map&lt;Integer, Map&lt;String,Long&gt;&gt;</code></p>
  <pre class="lang-java prettyprint-override"><code>Function&lt;Stream&lt;CavePerson&gt;, Map&lt;Integer, Map&lt;String, Long&gt;&gt;&gt; getGenderByYear = 
      e -&gt; e.map(x -&gt; x.year)
            .collect(Collectors.groupingBy((CavePerson-&gt; CavePerson.gender), Collectors.counting()));
  </code></pre>
  <p>Am I missing something here?</p>