0

I have a

HashMap<String,Integer> wordMap = new HashMap<String,Integer>();

I need to print the elements in such a way that they are in decreasing order of Integer values and the if two strings have same Integer values, they must be displayed in alphabetical order.
i.e If

HashMap={(it,2),(worst,1),(the,2),(of,2)}

,
The output should be::

it-2
of-2
the-2
worst-1
jmj
  • 237,923
  • 42
  • 401
  • 438

1 Answers1

0

You could use a LinkedHashMap and compare the items' individual values, by starting with the item at index 0 as the baseline.

Kyle Emmanuel
  • 2,193
  • 1
  • 15
  • 22