Difference Between ArrayList and Vector

Naveen AnamaneniUpdated · 3 min read

ArrayList and Vector are both classes that implement the List interface using a resizable array. They keep insertion order, allow duplicates and null, and give fast access by index. The key difference is that Vector is synchronized and ArrayList is not. In this lesson, you will learn all the differences between them and which one to choose.

Differences Between ArrayList and Vector

ArrayListVector
SynchronizationNot synchronizedSynchronized: every method takes a lock
Thread safetyNot thread-safeThread-safe for single method calls
PerformanceFasterSlower, because of locking
Growth when fullGrows by 50% (10, 15, 22...)Doubles (10, 20, 40...)
Initial capacity10, allocated on the first add10, allocated when created
Introduced inJava 1.2 (Collections Framework)Java 1.0 (legacy class)
IterationIterator, ListIteratorIterator, ListIterator and the old Enumeration
Legacy methodsNoneaddElement, elementAt, removeElement...
Custom growth stepNoYes: new Vector<>(capacity, increment)

Example: Same Operations, Different Classes

Let's see an example that runs the same code on both.

ListCompare.java▶ Try it
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
 
public class ListCompare {
    static void fill(List<String> list) {
        list.add("Navika");
        list.add("Srihitha");
        list.add("Advitha");
        list.remove(1);
        System.out.println(list.getClass().getSimpleName() + ": " + list);
    }
 
    public static void main(String[] args) {
        fill(new ArrayList<>());
        fill(new Vector<>());
    }
}
Output
ArrayList: [Navika, Advitha]
Vector: [Navika, Advitha]

Explanation: Both classes implement List, so the same method works with either and gives the same result. The difference isn't in what they do but in how they do it: each Vector call takes a lock, and each ArrayList call doesn't.

Which One to Use

  • One thread: use ArrayList. It is faster and is the standard choice.
  • Many threads, mostly reading: use CopyOnWriteArrayList.
  • Many threads, mixed reads and writes: use Collections.synchronizedList(new ArrayList<>()) with your own locking around compound actions, or a concurrent queue.
  • Vector: only when maintaining old code that already uses it.

Common Mistakes

Believing Vector is the "thread-safe ArrayList" that solves every concurrency problem. Only single calls are protected.

Choosing Vector for speed. It is slower than ArrayList in single-threaded code.

Interview Corner

What is the difference between ArrayList and Vector?

Both are resizable-array implementations of List. Vector is a legacy class from Java 1.0 whose methods are all synchronized, which makes it thread-safe for single operations but slower. ArrayList, added in Java 1.2, isn't synchronized and is faster. When full, ArrayList grows by 50% while Vector doubles by default. Vector also supports the legacy Enumeration and methods such as addElement. New code should use ArrayList, or a concurrent collection when threads share the list.

Practice

  1. Easy: Add 100 elements to an ArrayList and a Vector, then explain why their capacities differ.
  2. Harder: Start two threads that each add 10,000 elements to a shared ArrayList, and print the final size. Repeat with a Vector. Explain the results.

Quick check: ArrayList vs Vector

4 questions
1Which is synchronized?
2Which is faster in single-threaded code?
3How does Vector grow by default?
4Which supports Enumeration?

Key Takeaways

Was this tutorial helpful?

Lesson 265 of 482