title: How to sort a HashMap based on values in descending order?
body: <p>I'm trying to sort a <code>HashMap</code> based on <em>values</em>, so that its ordered in <em>descending order</em>. But I have no idea on how to implement it. How would I go about doing it?</p>
  
  <pre><code>HashMap&lt;K, Integer&gt; keysAndSizeMap = new HashMap&lt;&gt;();
  
  for (K set : map.keySet()) {
       keysAndSizeMap.put(set, map.get(set).size());
  }
  
  // implementation here?
  
  System.out.println("keysAndSizeMap: " + keysAndSizeMap);
  </code></pre>
  
  <p>Example of the result I want:</p>
  
  <ul>
  <li>input: <code>{800=12, 90=15, 754=20}</code></li>
  <li>output: <code>{754=20, 90=15, 800=12}</code></li>
  </ul>
  
  <p>-or-</p>
  
  <ul>
  <li>input: <code>{"a"=2, "b"=6, "c"=4}</code></li>
  <li>output: <code>{"b"=6, "c"=4, "a"=2}</code></li>
  </ul>