-1

My data is in the form of key value.i want to sort values.i have stored them in hashmap.

map.put(1,.8678)
map.put(2,.9578) map.put(6,.0453)

i want output:

(6,.0453), (1,.8678), (2,.9578)

I want to sort values, retrive sorted values and their keys efficient(with the least complexity).What is the best data structure for my problem? Thanks.

csperson
  • 901
  • 3
  • 12
  • 17
  • http://stackoverflow.com/questions/109383/how-to-sort-a-mapkey-value-on-the-values-in-java || this was answered before, it may help you. – Adly Aug 26 '13 at 08:11
  • You could create a `Pair` class that wraps the two values then sort with a custom comparator. You can store the pairs in a set using an appropriate hashcode/equals. – assylias Aug 26 '13 at 08:16
  • @MuhammedRamadanAdly none of the answeres has tick beside it. – csperson Aug 26 '13 at 08:29

1 Answers1

-1

use a TreeMap instead of a hashmap

Thudani Hettimulla
  • 754
  • 1
  • 12
  • 32