title: Python Counter alternative for Java
body: <p>I have been using the Counter() data structure in Python as a key-value store that allows me to have the objects sorted according to their value using the most_common method. More info <a href="https://docs.python.org/2/library/collections.html#collections.Counter" rel="noreferrer">here</a>.</p>
  
  <p>Is there any similar data structure for the Java language? For example, I have seen many related answers that focus on sorting <a href="https://stackoverflow.com/questions/780541/how-to-sort-a-hashmap-in-java">HashMaps</a> or <a href="https://stackoverflow.com/questions/2864840/treemap-sort-by-value">TreeMaps</a> by the data structure is not initially defined for that purpose. In my case I usually need to to keep counters of objects and then to select the most common or the ones with the highest score (Top-N queries). However, it is difficult for me since I need to insert to a HashMap and then sort or to use multiple data structures.</p>