Sequential Map

I need to:

  1. retrieve values using keys
  2. be able to iterate the contents in the order they were inserted.

I can’t find this functionality in any of the Maps. Have I missed one or I must I make my own? If thats the case, how to make it speedy for get and iteration.

Don’t believe there exist a Map that does exactly this. I would suggest you make your own class using a Hastable for 1) and a Vector for 2).

The other option would be to use a SortedMap where you use your own Comparable interface. But I guess you would have to bake in a insertion id in the key.

You could always wrap a list and a map into one object. It might save you worrying about implemenation and you could rely on the exiting collections for performance.

Kev

Would using two Arrays be a good idea?

String [] keys;
Object [] values;

I don’t need to modify its contents beyond initialization of the program.

If you haven’t already examined it, check out
java.util.LinkedHashMap. I’ve found it very useful
on specific occassions.

LinkedHashMap worked perfectly. I wonder if a I would gain anything by implementing my own thing based on Arrays? Isn’t Arrays the most effiecient way to iterate objects?

You could gain a little bit speed with implementing that. but i don’t think it’s worth the work ;).

Never forget: write first, profile, fix all things that are too slow.

Don’t try to optimize before profiling :D.

troggan