dcsimg
Sorting Hastable according to Values
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Nishant_Sheth
Posted On:   Wednesday, May 23, 2001 11:21 PM

Hello Friends, I am developing a shopping card. I have three different products say Toys,Gifts & Side Products. I have developed a table in mysql which has the following details: CategoryId CategoryName 1 Toys 2 Gifts 3 Side Products And when the user selects any item from the above category I am putting the values in the String array like price,productname categoryid etc... as value. And this string array is stored in a hastable as key/value. I would like to sort the hastable according to the categoryid which is stored in a String array and this String array is stored in a hastable. Thanks    More>>

Hello Friends,

I am developing a shopping card. I have three different products say Toys,Gifts & Side Products. I have developed a table in mysql which has the following details:

CategoryId CategoryName

1 Toys

2 Gifts

3 Side Products


And when the user selects any item from the above category I am putting the values in the String array like price,productname categoryid etc... as value. And this string array is stored in a hastable as key/value.

I would like to sort the hastable according to the categoryid which is stored in a String array and this String array is stored in a hastable.


Thanks

   <<Less

Re: Sorting Hastable according to Values

Posted By:   Christopher_Schultz  
Posted On:   Thursday, May 24, 2001 08:20 AM

Well, you can't sort a hashtable, but you can get all of the values in a hashtable and sort THEM.





Collection values = hashtable.values();
LinkedList list = new LinkedList(values);

list = Collections.sort(list);



You now have a sorted list of your values. Note that the values are still not sorted in the hashtable, since that doesn't make any sense. Only the list we created has any notion of 'order'.



-chris
About | Sitemap | Contact