title: Java 8 stream to Map<Integer, List<String>>
body: <p>This is Java object to handle in Java 8 stream</p>
  
  <pre><code>private static List&lt;Person&gt; getPersons() {
          List&lt;Person&gt; results = new ArrayList&lt;Person&gt;();
  
          results.add(new Person("Elsdon", "Jaycob", "Java programmer", "male", 43, 2000));
          results.add(new Person("Tamsen", "Brittany", "Java programmer", "female", 23, 1500));
          results.add(new Person("Floyd", "Donny", "Java programmer", "male", 33, 1800));
          results.add(new Person("Sindy", "Jonie", "Java programmer", "female", 32, 1600));
          results.add(new Person("Vere", "Hervey", "Java programmer", "male", 22, 1200));
          results.add(new Person("Maude", "Jaimie", "Java programmer", "female", 27, 1900));
          results.add(new Person("Shawn", "Randall", "Java programmer", "male", 30, 2300));
          results.add(new Person("Jayden", "Corrina", "Java programmer", "female", 35, 1700));
          results.add(new Person("Palmer", "Dene", "Java programmer", "male", 33, 2000));
          results.add(new Person("Addison", "Pam", "Java programmer", "female", 34, 1300));
  
          results.add(new Person("Jarrod", "Pace", "PHP programmer", "male", 34, 1550));
          results.add(new Person("Clarette", "Cicely", "PHP programmer", "female", 23, 1200));
          results.add(new Person("Victor", "Channing", "PHP programmer", "male", 32, 1600));
          results.add(new Person("Tori", "Sheryl", "PHP programmer", "female", 21, 1000));
          results.add(new Person("Osborne", "Shad", "PHP programmer", "male", 32, 1100));
          results.add(new Person("Rosalind", "Layla", "PHP programmer", "female", 25, 1300));
          results.add(new Person("Fraser", "Hewie", "PHP programmer", "male", 36, 1100));
          results.add(new Person("Quinn", "Tamara", "PHP programmer", "female", 21, 1000));
          results.add(new Person("Alvin", "Lance", "PHP programmer", "male", 38, 1600));
          results.add(new Person("Evonne", "Shari", "PHP programmer", "female", 40, 1800));
  
          return results;
      }
  </code></pre>
  
  <p>And I generate Map objects with key-value <strong>"age"</strong>. This is codes</p>
  
  <pre><code>    Function&lt;Person, Map&lt;String, String&gt;&gt; nameNsalary = (Person p) -&gt; {
                  Map&lt;Int, String&gt; map = new HashMap&lt;Int,String&gt;();
  
                  if (p.getAge()&gt;=40)
                      map.put(40 , p.getFirstName() + " " + p.getLastName() +":" + p.getSalary());
                  else if(p.getAge()&gt;=30 &amp;&amp; p.getAge()&lt;40)
                      map.put(30 , p.getFirstName() + " " + p.getLastName() +":" + p.getSalary());
                  else if(p.getAge()&lt;20)
                      map.put(20 , p.getFirstName() + " " + p.getLastName() +":" + p.getSalary());
                  else 
                      map.put(10 , p.getFirstName() + " " + p.getLastName() +":" + p.getSalary());
  
                  return map;
              };
  
  persons.stream().map(nameNsalary).forEach(System.out::println);
  </code></pre>
  
  <p>Output map object is successful like below,</p>
  
  <pre><code>{40=Elsdon Jaycob:2000}
  {20=Tamsen Brittany:1500}
  {30=Floyd Donny:1800}
  {30=Sindy Jonie:1600}
  {20=Vere Hervey:1200}
  {20=Maude Jaimie:1900}
  {30=Shawn Randall:2300}
  {30=Jayden Corrina:1700}
  {30=Palmer Dene:2000}
  {30=Addison Pam:1300}
  {30=Jarrod Pace:1625}
  {20=Clarette Cicely:1260}
  {30=Victor Channing:1680}
  {20=Tori Sheryl:1050}
  {30=Osborne Shad:1155}
  {20=Rosalind Layla:1365}
  {30=Fraser Hewie:1155}
  {20=Quinn Tamara:1050}
  {30=Alvin Lance:1680}
  {40=Evonne Shari:1890}
  </code></pre>
  
  <p>But I fail changing output type from <code>Map&lt;Integer, String&gt;</code> to <code>Map&lt;Integer, List&lt;String&gt;&gt;</code>, for example,</p>
  
  <pre><code>30 = [Jayden Corrina:1700, Palmer Dene:2000, Addison Pam:1300]
  </code></pre>
  
  <p>I have no idea how to handle these Map object data to <code>Map&lt;Int, List&lt;String&gt;&gt;</code>. I made this code, </p>
  
  <pre><code>Map&lt;Integer, List&lt;String&gt;&gt; result = persons.stream().map(nameNsalary)
                  .collect(Collectors.toMap(mapper -&gt; (Integer)mapper.getKey(), mapper -&gt; mapper.getValue()));
  </code></pre>
  
  <p>But this code throws the following exception</p>
  
  <pre><code>Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
      Type mismatch: cannot convert from Map&lt;Object,Object&gt; to Map&lt;Integer,List&lt;String&gt;&gt;
      The method getKey() is undefined for the type Map&lt;Integer,String&gt;
      The method getValue() is undefined for the type Map&lt;Integer,String&gt;
  </code></pre>
  
  <p>I am stuck with this procedure.</p>