title: Java 8 Streams: collector returning filtered object
body: <p>Say I have a Set that I'd like to filter down to the oldest per school.</p>
  
  <p>So far I have:</p>
  
  <pre><code>Map&lt;String, Long&gt; getOldestPerSchool(Set&lt;Person&gt; persons) {
    return persons.stream().collect(Collectors.toMap(Person::getSchoolname, Person::getAge, Long::max);
  }
  </code></pre>
  
  <p>Trouble is, I want the whole person instead of only the name. But if I change it to:</p>
  
  <pre><code>Map&lt;Person, Long&gt; getOldestPerSchool(Set&lt;Person&gt; persons) {
    return persons.stream().collect(Collectors.toMap(p -&gt; p, Person::getAge, Long::max);
  }
  </code></pre>
  
  <p>I get all persons, and I do not necessarily need a Map.</p>