Using Java, assuming v1.6.
I have a collection where the unique index is a string and the non-unique value is an int. I need to perform thousands of lookups against this collection as fast as possible.
I currently am using a HashMap<String, Integer>
but I am worried that the boxing/unboxing of the Integer to int is making this slower.
I had thought of using an ArrayList<String>
coupled with an int[]
.
i.e. Instead of:
int value = (int) HashMap<String, Integer>.get("key");
I could do
int value = int[ArrayList<String>.indexOf("key")];
Any thoughts? Is there a faster way to do this?
p.s. I will only build the collection once and maybe modify it once but each time I will know the size so I can use String[]
instead of ArrayList
but not sure there's a faster way to replicate indexOf...