Sorting Issue with the Usage of Hashtable
4 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Shreya_Sreejith
Posted On:   Thursday, September 29, 2005 12:28 PM

I need to fetch a set of values (which are already in sorted order) from the database through hashtable. However, while retreiving the values from the hashtable, the sorting order is lost. Why is it so?
What can be a possible solution?
Will the usage of Arraylist will solve the issue here?

Re: Sorting Issue with the Usage of Hashtable

Posted By:   Prasanna_Talakanti  
Posted On:   Wednesday, December 7, 2005 01:37 PM


The reason is simple (hashtable does not gaurantee the order, Not all the map implementations gaurantee the order), If you want to retrieve the order in which you added the objects to a Map (use LinkedHashMap), According to sun it is not as efficient as (Hashmap/table), But i would say it is not that bad

Re: Sorting Issue with the Usage of Hashtable

Posted By:   Anonymous  
Posted On:   Tuesday, October 11, 2005 06:48 AM

Hashtable and Hashmap do not guarantee the order of the objects. If you are using JDK1.4, use LinkedHashMap, this is backed by an ArrayList, so the order of insertion is guaranteed.

Re: Sorting Issue with the Usage of Hashtable

Posted By:   Anonymous  
Posted On:   Friday, September 30, 2005 06:26 AM

Hi Shreya,

using Hashtable we can put and get the java objects relatively fast. But Hashtable does not maintain the order in which you add and retrieve the objects. U can use a ArrayList to maitain the order .if u need a Key value pair collection then u can maintain two ArrayLists...


-Krishna Rajendra Alapati

Re: Sorting Issue with the Usage of Hashtable

Posted By:   Almagest_FUTT  
Posted On:   Thursday, September 29, 2005 01:14 PM

Use an instance of java.util.SortedMap.
About | Sitemap | Contact