title: Java How to return top 10 items based on value in a HashMap
body: <p>So I am very new to Java and as such I'm fighting my way through an exercise, converting one of my Python programs to Java.  </p>
  
  <p>I have run into an issue where I am trying to replicate the behavior, from python the following will return only the keys sorted (by values), not the values:</p>
  
  <pre><code>popular_numbers = sorted(number_dict, key = number_dict.get, reverse = True)
  </code></pre>
  
  <p>In Java,  I have done a bit of research and have not yet found an easy enough sample for a n00b such as myself or a comparable method.  I have found examples using Guava for sorting, but the sort appears to return a HashMap sorted by key. </p>
  
  <p>In addition to the above, one of the other nice things about Python, that I have not found in Java is the ability to, easily, return a subset of the sorted values.  In Python I can simply do the following:</p>
  
  <pre><code>print "Top 10 Numbers: %s" % popular_numbers[:10]
  </code></pre>
  
  <p>In this example, number_dict is a dictionary of key,value pairs where key represents numbers 1..100 and the value is the number of times the number (key) occurs:</p>
  
  <pre><code>for n in numbers:
   if not n == '':
     number_dict[n] += 1
  </code></pre>
  
  <p>The end result would be something like:</p>
  
  <blockquote>
    <p>Top 10 Numbers: ['27', '11', '5', '8', '16', '25', '1', '24', '32',
    '20']</p>
  </blockquote>
  
  <p>To clarify, in Java I have successfully created a HashMap, I have successfully examined numbers and increased the values of the key,value pair.  I am now stuck at the sort and return the top 10 numbers (keys) based on value.</p>