GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection
  • Introduction3 min read
  • Variables2 min read
  • Data Types7 min read
  • Operators7 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — Vector vs ArrayList in Java - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection

Vector vs ArrayList in Java

Last Updated : 9 Jun, 2026

Vector and ArrayList are dynamic array implementations in Java used to store elements that can grow or shrink in size. Both are part of the java.util package and provide indexed access to elements.

  • Both allow duplicate elements and maintain insertion order.
  • Both provide fast index-based access to elements.
  • They differ mainly in performance and thread-safety behavior.

ArrayList

ArrayList is a resizable array implementation of the List interface that allows dynamic storage of elements. It is widely used because it provides fast random access and flexible size management.

  • Maintains insertion order of elements.
  • Not synchronized, so it is not thread-safe.
  • Grows dynamically when elements are added.

Syntax:

List<DataType> listName = new ArrayList<>();

Java
import java.util.ArrayList;

public class ArrayListExample {
    public static void main(String[] args) {

        // Creating an ArrayList
        ArrayList<String> names = new ArrayList<>();

        // Adding elements
        names.add("Ravi");
        names.add("Aman");
        names.add("Neha");
        names.add("Priya");

        // Displaying ArrayList
        System.out.println("Names: " + names);

        // Accessing element using index
        System.out.println("Element at index 2: " + names.get(2));

        // Removing an element
        names.remove("Aman");

        // Updated ArrayList
        System.out.println("After removal: " + names);

        // Size of ArrayList
        System.out.println("Total Elements: " + names.size());
    }
}

Output
Names: [Ravi, Aman, Neha, Priya]
Element at index 2: Neha
After removal: [Ravi, Neha, Priya]
Total Elements: 3

Vector

Vector is a dynamic array implementation in Java that grows automatically when elements are added. It is similar to ArrayList but it is synchronized and thread-safe.

  • Vector is a legacy class introduced in Java 1.0 before the Collection Framework.
  • Maintains insertion order of elements.
  • Slower than ArrayList due to synchronization overhead.. 

Syntax:

Vector<DataType> vectorName = new Vector<>();

Java
import java.util.Vector;

public class VectorExample {
    public static void main(String[] args) {

        // Creating a Vector
        Vector<String> names = new Vector<>();

        // Adding elements
        names.add("Ravi");
        names.add("Aman");
        names.add("Neha");
        names.add("Priya");

        // Displaying Vector
        System.out.println("Names: " + names);

        // Accessing element using index
        System.out.println("Element at index 1: " + names.get(1));

        // Removing an element
        names.remove("Aman");

        // Updated Vector
        System.out.println("After removal: " + names);

        // Size of Vector
        System.out.println("Total Elements: " + names.size());
    }
}

Output
Names: [Ravi, Aman, Neha, Priya]
Element at index 1: Aman
After removal: [Ravi, Neha, Priya]
Total Elements: 3

ArrayList vs Vector 

FeatureArrayListVector
IntroductionIntroduced in Java 1.2 (Collection Framework)Legacy class (Java 1.0)
Packagejava.utiljava.util
SynchronizationNot synchronizedSynchronized (thread-safe)
PerformanceFaster (no synchronization overhead)Slower due to synchronization
Growth MechanismIncreases size by 50% when fullDoubles size when full (by default)
Thread SafetyNot thread-safeThread-safe
Preferred UseSingle-threaded applicationsMulti-threaded applications (rarely used today)
TraversalIteratorIterator + Enumeration (legacy support)
Comment

Explore

    Basics
    • Introduction3 min read
    • Variables2 min read
    • Data Types7 min read
    • Operators7 min read
    • Decision Making5 min read
    • Methods7 min read
    • Arrays7 min read
    • Strings5 min read
    OOP & Interface
    • Introduction6 min read
    • Constructors6 min read
    • Encapsulation3 min read
    • Inheritance8 min read
    • Polymorphism5 min read
    • Abstraction5 min read
    • Interfaces8 min read
    Collections
    • Collection class9 min read
    • Collection Interface5 min read
    • List Interface8 min read
    • Set Interface5 min read
    • Queue Interface5 min read
    • Map Interface in Java6 min read
    • Iterator4 min read
    Advance Java Concepts
    • Exception handling6 min read
    • Java Multithreading Tutorial3 min read
    • Synchronization in Java9 min read
    • File handling6 min read
    • Method References3 min read
    • Java 8 Stream Tutorial7 min read
    • Memory Management4 min read
    • Garbage Collection in Java6 min read
    • Networking6 min read
    • JDBC5 min read
    Practice Java
    • Interview Questions15+ min read
    • Programs6 min read
    • Practice Problems5 min read
    • Quiz1 min read
    • Project Ideas15+ min read
    Courses
    • Java Backend Course2 min read
    • Placement 360 Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.