wood burning stoves
The moose likes Java in General and the fly likes Comparison of Vector and ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Comparison of Vector and ArrayList" Watch "Comparison of Vector and ArrayList" New topic

Comparison of Vector and ArrayList

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
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

Joined: Aug 25, 2003
Posts: 504
Read this:
List Interface by Thomas Paul
Joe Ess

Joined: Oct 29, 2001
Posts: 9191

Similar analysis and conclusions in this article from Javaworld

[How To Ask Questions On JavaRanch]
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
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.
I agree. Here's the link: http://aspose.com/file-tools
subject: Comparison of Vector and ArrayList
It's not a secret anymore!