Forums Register Login

Map without sorting or hashing of keys

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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 ]
It means our mission is in jeapordy! Quick, read this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 5644 times.
Similar Threads
TreeMap
hashCode()/equals()
Remote method/argumet data structure
Maps and duplicates
Question regarding Map interface
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 23:19:56.