How to sort HashMap based on the values. I tried to overload compareTo method. But, I realized that I should be using Integer instead of Float
Asked
Active
Viewed 52 times
0
-
can you show your code – KVK May 03 '16 at 03:58
-
A HashMap is not sorted. Do you mean you want to have a list of all values in a sorted order? – Thilo May 03 '16 at 03:58
-
Hope this link could help: http://stackoverflow.com/questions/109383/sort-a-mapkey-value-by-values-java – soorapadman May 03 '16 at 03:59
-
I have `public static HashMap
cosineSim = new HashMap – Amuktha Chakilam May 03 '16 at 04:03();` This needs to be sorted based on the value. -
@AmukthaChakilam this link may be helps you https://gist.github.com/akhikhl/8153642 – KVK May 03 '16 at 04:06
-
@KVK tried to overload Comparator but, I wasn't to do so because of the return type I hold, which is float and not int. – Amuktha Chakilam May 03 '16 at 04:20