Question : Performance: HashMaps vs Arrays

I am writing a simulation program where speed is crucial.  From an OO design perspective, it makes most sense for me to use HashMaps whose keys are enum values in my model objects.  

I will be doing millions of operations on these HashMaps, looping over them many times, and doing lookups on them, including retrieving lists of keys whose value is equal to some specified value.

My question is this: Should I go ahead and use HashMaps, or should I consider using arrays, or some other structure, because they will be faster for these looping and lookup operations?

Thanks for any ideas.  I can give further details on what I'm doing if necessary.

Answer : Performance: HashMaps vs Arrays

Map will certainly be faster for the lookup as you would need to loop thru the array to lookup using an array.
For looping thru all elements then an array would be faster but probably not a lot in it (you'd need to do some benchmarking)

Though theres no reason you couldn't maintain an array and a Map, and use the array for looping, and the map for lookups

Random Solutions  
 
programming4us programming4us