array vs. hashmap
Posted on 2011-02-28
I had the question posed to me: "I need to store and retrieve some integers in my Java code. I don't exactly know how many integers at compile time. But I know it will be around 5,000 and definitely less than 5,500. This storage will be accessed frequently and I need a fast turn around time. Should I use: array, arraylist, vector, or hashmap? "
Based on my understanding, I selected hashmap, yet array was the correct answer. Why? I had always been told that hashmaps are faster.
Thanks for any clarification