Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between ArrayList, LinkedList and Vector

 
Santosh Nijalingappa
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between ArrayList, LinkedList and a Vector?. All that i know is that they implement the List Interface.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  • ArrayList is in most cases what you want to use. It is a list backed by an array, which means it has fast access to each element via the get method.
  • Vector is a leftover from the early days of Java, retrofitted with the List interface. The chief difference from ArrayList is that its methods are synchronized (ArrayList's are not). That means it is easier to use in multi-threaded environments, but it does incur the synchronization overhead.
  • LinkedList is backed by a doubly-linked list, not an array. That means it's fast to access elements at the start and the end of the list, but less so in the middle. On the other hand, inserting and deleting elements is fast compared to ArrayList.


  • [ February 10, 2008: Message edited by: Ulf Dittmer ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic