• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparison of Vector and ArrayList

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the performance difference between Vector and ArrayList in terms of time and memory. What are the basis of choosing one over the other.
 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read this:
List Interface by Thomas Paul
 
Joe Ess
Bartender
Posts: 9256
9
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Similar analysis and conclusions in this article from Javaworld
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The collections framework is constantly being re-worked, and so just for fun I did a little analysis of my own using JDK 1.4.2_02 as the baseline. I created an ArrayList and a Vector and did the following
-- Add/insert 100,000 elements
-- Get (randomly) 100,000 elements
-- Iterate through the elements
-- Remove (randomly) 75,000 elements
And guess what? The difference between using an ArrayList and Vector was statistically insignificant: the execution time was basically the same after averaging several runs.
If you look at the source code [supplied when you download the JDK] you'll see that the internal implementation of the two classes is very similar, which explains the performance.
I personally prefer to use ArrayList, but some "older" APIs work with Vectors and not ArrayList, and in those cases I'll fall back on using a Vector.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic