title: Java 8 re-map with modified value
body: <p>I'm about to get a grasp on the new Java 8 stream and lambda options, but there are still a few subtleties that I haven't yet wrapped my mind around.</p>
  
  <p>Let's say that I have a map where the keys are the names of people. The value for each name is a map of ages and <code>Person</code> instances. Further assume that there does not exist more than one person with the same name and age.</p>
  
  <pre><code>Map&lt;String, NavigableMap&lt;Long, Person&gt;&gt; names2PeopleAges = new HashMap&lt;String, NavigableMap&lt;Long, Person&gt;&gt;();
  </code></pre>
  
  <p>After populating that map (elsewhere), I want to produce another map of the oldest person for each name. I want to wind up with a <code>Map&lt;String, Person&gt;</code> in which the keys are identical to those in the first map, but the value for each entry is the value of the value map for which the key of the value map has the highest number.</p>
  
  <p>Taking advantage of the fact that a <code>NavigableMap</code> sorts its keys, I can do this:</p>
  
  <pre><code>Map&lt;String, Person&gt; oldestPeopleByName = new HashMap&lt;String, Person&gt;();
  names2PeopleAges.forEach((name, peopleAges) -&gt; {
    oldestPeopleByName.put(name, peopleAges.lastEntry().getValue());
  });
  </code></pre>
  
  <p><strong>Question:</strong> Can I replace the last bit of code above with a single Java 8 stream/collect/map/flatten/etc. operation to produce the same result? In pseudo-code, my first inclination would be:</p>
  
  <pre><code>Map&lt;String, Person&gt; oldestPeopleByName = names2PeopleAges.forEachEntry().mapValue(value-&gt;value.lastEntry().getValue());
  </code></pre>
  
  <p>This question is meant to be straightforward without any tricks or oddities---just a simple question of how I can fully leverage Java 8!</p>
  
  <p><strong>Bonus:</strong> Let's say that the <code>NavigableMap&lt;Long, Person&gt;</code> above is instead merely a <code>Map&lt;Long, Person&gt;</code>. Could you extend the first answer so that it collects the person with the highest age value, now that <code>NavigableMap.lastEntry()</code> is not available?</p>