posted 20 years ago
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.