title: How to group a set of objects into sorted lists using java 8?
body: <p>I want to take a set of objects (<code>ObjectInstance</code> in this case), and I want to group them by one property, and have the resulting lists be sorted on another.</p>
  
  <pre><code>Set&lt;ObjectInstance&gt; beans = server.queryMBeans(null, null);
  Map&lt;String, List&lt;String&gt;&gt; beansByDomain = beans.stream()
              .collect(groupingBy( (ObjectInstance oi) -&gt; oi.getObjectName().getDomain(),
                                  mapping((ObjectInstance oi) -&gt; oi.getObjectName().getCanonicalKeyPropertyListString(),
                                  toList() )));
  </code></pre>
  
  <p>The above expression creates the correct data structure: a <code>Map</code> where the keys are the domains of the <code>ObjectInstance</code> objects, and the values are Lists of the property lists.  What I want is to now sort the Lists, to make sure they are in alphabetical order.  Is there some way to do this in the same expression?</p>
  
  <p>One idea would be to add <code>.sort()</code> right after <code>.stream()</code>, but is that really guaranteed to work?</p>