aspose file tools*
The moose likes Java in General and the fly likes Hashtable / HashMap Problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Hashtable / HashMap Problem." Watch "Hashtable / HashMap Problem." New topic
Author

Hashtable / HashMap Problem.

L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Hi,
I am using Hashtable or HashMap to keep Key-Value pair of elements.
But When I add them, The Hashtable or HashMap gets sorted depending on the keys.
I want to retain the order in whcih I have added the key-value pair.
Is there anyway to do it with Hashtable or HashMap ?
Or Can I use any other Collection type which will have the mapping of key-value which is not sorted other than two dimensional Array.

Thanks for the time.


<b>L G Goundalkar</b><br /> <a href="mailto:lggoundalkar@yahoo.com" rel="nofollow">lggoundalkar@yahoo.com</a> <br />Sun Certified Programmer for Java 2 Platform.<br />Sun Certified Web Component Developer for J2EE.
Graeme Brown
Ranch Hand

Joined: Oct 13, 2000
Posts: 193
LinkedHashMap, available in JDK1.4, does what you want
Rahul Gupta
Ranch Hand

Joined: Nov 20, 2002
Posts: 37
The hash code is calculated using some function and depends on the hash key entered. It cannot be assured in general where in the Map/Table the key gets inserted. The Map/Table may or maynot get sorted after each implementation. It depends entirely on how the hash code calculating function is internally implemented.
regards,
Rahul Gupta :roll:


regards,<p>rahul <p>SCJP 1.4<br />--------<br />Life is great, make it meaningful<br />---------------------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hashtable / HashMap Problem.
 
Similar Threads
Storing ActionForm&action class-WHERE?
Passing object to excel spreadsheet
can a arraylist be converted into HashMap?
Sorting Problem
Which java Collections Shall i Use?