Is it possible to recover from an 'Hashtable' object the elements in the same entry order?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Beatriz_Castro
Posted On:   Thursday, April 26, 2001 08:41 AM

Is it possible to recover from an 'Hashtable' object the elements in the same entry order?

Congratulations for your articles and books. I find them very useful.

Regards from Spain.

Re: Is it possible to recover from an 'Hashtable' object the elements in the same entry order?

Posted By:   John_Zukowski  
Posted On:   Thursday, April 26, 2001 12:32 PM

Wait til Java 1.4...... You'll get a LinkedHashMap and LinkedHashSet which preserve insertion order.

Re: Is it possible to recover from an 'Hashtable' object the elements in the same entry order?

Posted By:   Julian_Cox  
Posted On:   Thursday, April 26, 2001 09:07 AM

NO is the simple answer. The purpose of the HashTable is to immediately sort any added objects for efficient retrieval by their key.



Possible solutions: consider creating a second collection of references such as a Vector and add to that at the same time. The Vector will maintain entry-order unless you change it.



Remember this doesn't create a set of duplicate objects! You will have one 'pool' of objects but two ways of referencing them - by key using the HashTable and by Entry order using the Vector - similar to 2 indexes on a table.



Another tip: If using Java 1.2 or later consider changing your HashTable to HashMap or HashSet and using the Collections framework interfaces throughout - will give you flexibility in the future to change your collection.

About | Sitemap | Contact