2

I have a java Map

   Map<String , String>

The map is like following

 olah : 3
 vola : 2
 sola : 5
 jingle : 9

i want to sort the map on the value string like sort on 3,2,5,9 for example...is there any efficient way possible.

I also want to know what difference it will make if i put a map with same values but like

Map<String , long> 

Does it improve any performance...?

Saurabh Kumar
  • 16,353
  • 49
  • 133
  • 212
  • See link here... http://stackoverflow.com/questions/109383/how-to-sort-a-mapkey-value-on-the-values-in-java – kaushik0033 Oct 22 '13 at 10:12
  • The basic is this: you can't. A map is a map is a map. What you **can** do, however, is to get the values as list and sort that list. – Ingo Oct 22 '13 at 10:17

1 Answers1

0

See: Sort a Map<Key, Value> by values (Java)

Something like

Map<String , long> 

is not possible because Java Collections can not store primitive types. If you want to do that, you can use fastutil http://fastutil.di.unimi.it/ or trove http://trove.starlight-systems.com/. Memory consumption will be better, since no Long objects are created.

Community
  • 1
  • 1
user2737086
  • 309
  • 3
  • 6