Well in simple terms the main difference between ArrayList,Vector with LinkedList is linkedlist is sequetinal access mechanisam. Hence linkedlist is preferred where you wish to get the list of values in a sequential manner and Arraylist/vector is perferred where you need random lookup of values. now the difference between vector and arraylist is vector is syncronized where as arraylist is not. Hope this helps
Originally posted by Lawrence Chettiar: Hence linkedlist is preferred where you wish to get the list of values in a sequential manner and Arraylist/vector is perferred where you need random lookup of values.
That is not really correct. Both, ArrayList and LinkedList are Lists and thus store the values in an ordered fashion. Search for a random element will require a serial lookup through the whole list. Advantages and disadvantage of ArrayList and LinkedList arise from the fact that ArrayList is based on an array while LinkedList is beased on a linked list. Therefore, adding and removing elements from the middle of the list will be faster in a LinkedList than in an ArrayList (because of the shift of element positions). For this reason, stack style operation are faster in a LinkedList. Memorywise, ArrayList should be more efficient than a LinkedList because LinkedList stores two references (front and back) per element. ArrayList will also be more efficient if you want to add tons on elements in one shot and then just reading the List (not adding/removing values). HTH, Paul.
LinkedList is much poorer than ArrayList for access by means of an index as it requires a sequential scan from the front or back of the list, ie not random access at all. ArrayList has fast random access as it is backed by an array, whereas LinkedList is doubly-linked list. Both are pretty good at iterating through a list, both retrieve in insertion order. What hasn't been mentioned yet is that a LinkedList can simulate a stack, queue or double-ended queue (deque). So, if you want to implement something like a FIFO queue, then linkedLIst has the methods to add and remove the first elements in the list.
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Joined: Dec 20, 2001
If you look into the two articles I indicated earlier, you'll find actual benchmarks for performance of the various collections. Perhaps perusing those articles would be worth-while.
Let me summarize all your tots LinkedList -Sequential Access -Non-synchornized -Use index -FIFO, stack, dequeu Vector -Random Access -Synchronized ArrayList -Random Access -Non-synchronized -resize itself Anymore things to add ?
Joined: May 05, 2003
Just read the two articles, do you have the Map interface version. Both articles are great !!
The Map article is in the August 2002 newsletter at : Collections3
Joined: Sep 29, 2002
Robbie, ArrayList is the modern version of Vector. It is faster, largely because it is not synchronized. Use ArrayList for new code. If you have to use Vector, normally because you are modifying existing code or dealing with some method which requires a vector, try and get accustomed to the new way of working. You can do this because Vector has been re-engineered to bring it into line with the Collections Framework way of working. For instance, use List's add method rather than addElement to add an element to the end of the vector. Or use iterator to return an Iterator rather than elements to return an Enumeration.