• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Anybody tell me the difference ?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
can anybody tell me the difference between
LinkedList , ArrayList and Vector
Thanks !!
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Preszio let
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Lawrence.
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also look at some Newsletter articles:
Collections 1
Collections 2
The first artciles covers lists while the second one covers sets.
I hope that helps,
Corey
 
Enthuware Software Support
Posts: 4810
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Do you think Performance is included in SCJP ?
 
Robbie kyodo
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Robbie kyodo
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just read the two articles, do you have the Map interface version.
Both articles are great !!
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Map article is in the August 2002 newsletter at : Collections3
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should never use Vector. If you need a synchronized List then use the synchronization method of the Collections class:
The fourth and final article
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic