This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Map without sorting or hashing of keys Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Map without sorting or hashing of keys" Watch "Map without sorting or hashing of keys" New topic
Author

Map without sorting or hashing of keys

Rohan Baweja
Ranch Hand

Joined: Aug 19, 2001
Posts: 31
I am looking for a data structure which is like a Map. I have used different classes from the standard api that implement the Map interface. All of them seem to move the data after its been added to the Map. TreeMap sorts according to the keys and HashMap hashes the keys. I am looking for a Map that stores the data in the same sequence as it was added, and also supports standard Map methods.
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Why do they have to be in the same order?
As far as I know there's no maps that don't sort in some manner. You could use an ArrayList and have every other element be the key for the following elements value. Then by finding the indexOf your key and adding 1 you would find the value as well.
[ August 04, 2003: Message edited by: Ken Blair ]
Jaap van Hengstum
Greenhorn

Joined: Jul 24, 2003
Posts: 24
If you are using JDK 1.4 or higher, the LinkedHashMap class does what you want.
If you are using an earlier JDK, the SequencedHashMap class in the Jakarta Commons Collections does what you want.
[ August 04, 2003: Message edited by: Jaap van Hengstum ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Map without sorting or hashing of keys