title: Sort a Hashmap by Value in Java 8
body: <p>I've got a HashMap that I need sorting by value and I'm trying to keep it concise, so I'm using Java 8. However various methods aren't working and I'm unsure why. I've tried this:</p>
  
  <pre><code>followLikeCount.values()
    .stream()
    .sorted(Map.Entry.comparingByValue())
    .collect(Collectors.toList());
  </code></pre>
  
  <p>Which throws this compile time exception:</p>
  
  <pre><code>Main.java:65: error: no suitable method found for sorted(Comparator&lt;Entry&lt;Object,V#1&gt;&gt;)
    .sorted(Map.Entry.comparingByValue())
  </code></pre>
  
  <p>I can't see why there is a mismatch from observation. I've also tried using the comparator:</p>
  
  <pre><code>Comparator&lt;Map.Entry&lt;Integer, Integer&gt;&gt; byValue =
            Map.Entry.&lt;Integer, Integer&gt;comparingByValue();
  </code></pre>
  
  <p>Which yields a similar error. Please could you advise why the comparators aren't valid?</p>