title: Stream.collect(groupingBy(identity(), counting()) and then sort the result by value
body: <p>I can <a href="https://stackoverflow.com/questions/25441088/group-by-counting-in-java8-stream-api">collect a list of words into a bag</a> (a.k.a. multi-set):</p>
  
  <pre><code>Map&lt;String, Long&gt; bag =
          Arrays.asList("one o'clock two o'clock three o'clock rock".split(" "))
          .stream()
          .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
  </code></pre>
  
  <p>However, the entries of the bag are not guaranteed to be in any particular order. For example,</p>
  
  <pre><code>{rock=1, o'clock=3, one=1, three=1, two=1}
  </code></pre>
  
  <p>I can put them into a list, and then sort them using my implementation of a value comparator:</p>
  
  <pre><code>ArrayList&lt;Entry&lt;String, Long&gt;&gt; list = new ArrayList&lt;&gt;(bag.entrySet());
  Comparator&lt;Entry&lt;String, Long&gt;&gt; valueComparator = new Comparator&lt;Entry&lt;String, Long&gt;&gt;() {
  
      @Override
      public int compare(Entry&lt;String, Long&gt; e1, Entry&lt;String, Long&gt; e2) {
          return e2.getValue().compareTo(e1.getValue());
      }
  };
  Collections.sort(list, valueComparator);
  </code></pre>
  
  <p>This gives the desired result:</p>
  
  <pre><code>[o'clock=3, rock=1, one=1, three=1, two=1]
  </code></pre>
  
  <p>Is there a more elegant way to do this? I'm sure it's a problem many people must have solved. Is there something built into Java Streams API that I can use?</p>