Try using the System.currentMillis() and System.timeNanos() methods. Set a long number to the time before and after you run your method, and print out the difference. It will probably only be a microsecond or so, so you will probably find the nanosecond method more useful.
If it doesn't work, it is because I have given you the wrong name for the methods.
And I have gone back to the post to add:
Remember to tell us which works faster. [ April 15, 2006: Message edited by: Campbell Ritchie ]
Good reasons to use Map: You don't know the size of the collection ahead of time, the key is not an integer but maybe something like state abbreviation, the key is a number but there will be many gaps in the key sequence.
Good reasons to use index: The key is an integer, you won't skip any keys, you need fast access sequentially, maybe reverse order as well as random by key.
I'm kinda making those up as I go. Do try the timing comparison and see if I was right or if it makes much difference in your situation. And hide the decision within some class so you can change it in the future without breaking any other code.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi