Program to Convert a Vector to List in Java

Last Updated : 4 Sep, 2026

A Vector in Java can be converted into a List in several ways using the Collections Framework. The choice of method depends on whether you need a separate, modifiable list or a read-only view of the Vector.

  • Collections.list() converts the Vector's Enumeration into a new List.
  • new ArrayList<>(vector) creates a separate and modifiable list containing the Vector's elements.

Example:

Input: Vector: [10, 20, 30, 40, 50]
Output: List: [10, 20, 30, 40, 50]

Ways to Convert Vector to List in Java

1. Using Collections.list()

The Collections.list() method creates a List from an Enumeration. Since Vector.elements() returns an Enumeration, it can be passed directly to this method.

Syntax:

List<T> list = Collections.list(vector.elements());

Approach:

  1. Create a Vector and add elements to it.
  2. Get its Enumeration using elements().
  3. Pass the Enumeration to Collections.list().
  4. Print the resulting List.
Java
import java.util.*;

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

        Vector<Integer> vector = new Vector<>();

        vector.add(10);
        vector.add(20);
        vector.add(30);
        vector.add(40);
        vector.add(50);

        System.out.println("Vector: " + vector);

        List<Integer> list = Collections.list(vector.elements());

        System.out.println("List: " + list);
    }
}

Output
Vector: [10, 20, 30, 40, 50]
List: [10, 20, 30, 40, 50]

Explanation: vector.elements() returns an Enumeration of the Vector elements. Collections.list() converts that Enumeration into a new List.

2. Using Collections.unmodifiableList()

Collections.unmodifiableList() creates a read-only view of the Vector as a List. The returned list cannot be modified directly.

Syntax:

List<T> list = Collections.unmodifiableList(vector);

Approach:

  1. Create a Vector.
  2. Pass the Vector to Collections.unmodifiableList().
  3. Store the returned List.
  4. Print the List.
Java
import java.util.*;

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

        Vector<String> vector = new Vector<>();

        vector.add("Java");
        vector.add("Python");
        vector.add("C++");
        vector.add("Go");

        System.out.println("Vector: " + vector);

        List<String> list
            = Collections.unmodifiableList(vector);

        System.out.println("List: " + list);
    }
}

Output
Vector: [Java, Python, C++, Go]
List: [Java, Python, C++, Go]

Explanation: The returned List provides read-only access to the Vector. Operations such as list.add() or list.remove() will throw UnsupportedOperationException.

Note: This is a view of the original Vector, not an independent copy. Changes made directly to the Vector can be reflected in the List.

3. Using ArrayList Constructor

The ArrayList constructor can directly accept a Vector because Vector implements the List interface. This creates a separate ArrayList containing the same elements.

Syntax:

List<T> list = new ArrayList<>(vector);

Approach:

  1. Create a Vector and add elements.
  2. Pass the Vector to the ArrayList constructor.
  3. Store the result in a List.
  4. Print the List.
Java
import java.util.*;

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

        Vector<Double> vector = new Vector<>();

        vector.add(2.5);
        vector.add(4.5);
        vector.add(6.5);
        vector.add(8.5);

        System.out.println("Vector: " + vector);

        List<Double> list = new ArrayList<>(vector);

        System.out.println("List: " + list);
    }
}

Output
Vector: [2.5, 4.5, 6.5, 8.5]
List: [2.5, 4.5, 6.5, 8.5]

Explanation: new ArrayList<>(vector) copies all elements of the Vector into a new ArrayList. The resulting List can be modified independently of the original Vector.

Note: If you need a normal, independent and modifiable List, new ArrayList<>(vector) is usually the most straightforward approach.

Comment