here's m code
Integer max = Collections.max(map.values());
int count = 20;
while(count>0)
{
for (Map.Entry<String, Integer> e : map.entrySet())
if(e.getValue() == max)
{
System.out.println(e.getKey() + "occurs" + e.getValue() + "times");
count--;
}
max--;
}
This program runs in theta of n square time complexity. Is there a better way to display entries in the max which have top 20 maximum values in descending order?