title: Java 8 grouping using custom collector?
body: <p>I have the following class.</p>
  
  <pre><code>class Person {
  
      String name;
      LocalDate birthday;
      Sex gender;
      String emailAddress;
  
      public int getAge() {
          return birthday.until(IsoChronology.INSTANCE.dateNow()).getYears();
      }
  
      public String getName() {
          return name;
      }
  }
  </code></pre>
  
  <p>I'd like to be able to group by age and then collect the list of the persons names rather than the Person object itself; all in a single nice lamba expression.</p>
  
  <p>To simplify all of this I am linking my current solution that store the result of the grouping by age and then iterates over it to collect the names.</p>
  
  <pre><code>ArrayList&lt;OtherPerson&gt; members = new ArrayList&lt;&gt;();
  
  members.add(new OtherPerson("Fred", IsoChronology.INSTANCE.date(1980, 6, 20), OtherPerson.Sex.MALE, "fred@example.com"));
  members.add(new OtherPerson("Jane", IsoChronology.INSTANCE.date(1990, 7, 15), OtherPerson.Sex.FEMALE, "jane@example.com"));
  members.add(new OtherPerson("Mark", IsoChronology.INSTANCE.date(1990, 7, 15), OtherPerson.Sex.MALE, "mark@example.com"));
  members.add(new OtherPerson("George", IsoChronology.INSTANCE.date(1991, 8, 13), OtherPerson.Sex.MALE, "george@example.com"));
  members.add(new OtherPerson("Bob", IsoChronology.INSTANCE.date(2000, 9, 12), OtherPerson.Sex.MALE, "bob@example.com"));
  
  Map&lt;Integer, List&lt;Person&gt;&gt; collect = members.stream().collect(groupingBy(Person::getAge));
  
  Map&lt;Integer, List&lt;String&gt;&gt; result = new HashMap&lt;&gt;();
  
  collect.keySet().forEach(key -&gt; {
              result.put(key, collect.get(key).stream().map(Person::getName).collect(toList()));
  });
  </code></pre>
  
  <p><a href="http://ideone.com/wA60vl">Current solution</a></p>
  
  <p>Not ideal and for the sake of learning I'd like to have a more elegant and performing solution.</p>