Wednesday, April 30, 2008

Array, List and Map Differences...

The measured times show that for random operations within a list, it's preferable to use the array or the ArrayList. There's no real difference in performance between the array and the ArrayList, so if you need the extra features of an ArrayList, then it's the obvious choice. You should only consider using LinkedList when your operations work on the ends of the list. Another option to consider might be the new Queue class-- when only the top element of a list is of interest.

When the index or key to the list is not an integer, HashMap is the only choice, and as you've seen, its performance is quite good.

For details: Java Boutique



No comments: