dcsimg
Hashtable sorting by values
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ajay_Tejwani
Posted On:   Monday, September 24, 2001 09:38 AM

I have a hashtable with keys as Product codes and corresponsding values as their description. I have to read from the hashtable and display a Select box whose values for the options are the Keys of the Hashtable and the display are the values in the Hashtable. I have to sort the Values alphabetially so that they display becomes more friendly to users. How can I sort the Values of the Hashtable ? For e.g., --Select-- Carrots Peach Bananas And these have to sorted by the fruit names and not the values. Thanks in advance, Ajay    More>>

I have a hashtable with keys as Product codes and corresponsding values as their description.



I have to read from the hashtable and display a Select box whose values for the options are the Keys of the Hashtable and the display are the values in the Hashtable.



I have to sort the Values alphabetially so that they display becomes more friendly to users. How can I sort the Values of the Hashtable ?




For e.g.,

And these have to sorted by the fruit names and not the values.


Thanks in advance, Ajay

   <<Less

Re: Hashtable sorting by values

Posted By:   John_Zukowski  
Posted On:   Tuesday, September 25, 2001 01:27 AM

Use two maps. One in each direction. The second one should be a TreeMap so it is sorted. Use the second for display and the first for lookup.

Re: Hashtable sorting by values

Posted By:   Peter_McEvoy  
Posted On:   Monday, September 24, 2001 09:51 AM

I had the same problem, and to avoid messy coding, I decided to use a TreeSet object instead: It has similar functionality to HashTable, but the default set is ordered!
About | Sitemap | Contact