I am trying to sort my output of my program based on the number of occurrences of each key in the hashmap. I want it to print out in an increasing order of occurrences. It already prints out correctly, just not in order. I looked at this page Sort a Map<Key, Value> by values but its really confusing on what works still and what doesn't.
Hashmap -
Map<String, NumberHolder> uaCount = new HashMap<String, NumberHolder>();
Printing part
for(String str : uaCount.keySet())
{
String [] arr = str.split(":");
long average = uaCount.get(str).sumtime_in_milliseconds / uaCount.get(str).occurrences;
System.out.println(arr[0] + " ---> " + arr[1] + "---> " + arr[2] + "--->" + arr[3] + "\nAverage = " + average + " milliseconds \nOccurrences = " + uaCount.get(str).occurrences);
}
My NumberHolder
class defined
public static class NumberHolder
{
public int occurrences = 0;
public int sumtime_in_milliseconds = 0;
}