Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Map without sorting or hashing of keys

 
Rohan Baweja
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic