Convert Vector to ArrayList & ArrayList to Vector in Java Example

This example shows how to convert Vector to an ArrayList and ArrayList to a Vector in Java. This example also shows how to convert using the constructor and addAll method.

The ArrayList and Vector classes are implementations of the List interface.

How to convert Vector to ArrayList in Java?

The ArrayList class in Java provides a constructor that accepts a Collection object.

This constructor creates a new array list object containing all the elements of the specified collection object. We can use this constructor to convert a vector object to an ArrayList object as given below.

Output

We can also create an empty array list object and then use the addAll method of the ArrayList class to add all elements of the vector to the empty array list object.

Output

How to convert ArrayList to Vector in Java?

The Vector class also provides a constructor that accepts a Collection object as a parameter.

It creates a new vector object containing all the elements of the specified collection object. We can use this constructor to convert an ArrayList to a Vector object as given below.

Output

We can also create a new and empty object of the Vector class first and then add elements of the ArrayList to the new vector object using the addAll method as given below.

Output

This example is a part of the Java Vector Tutorial with Examples.

Please let me know your views in the comments section below.

References:
Java 8 Vector Documentation

About the author

RahimV

RahimV

My name is RahimV and I have over 16 years of experience in designing and developing Java applications. Over the years I have worked with many fortune 500 companies as an eCommerce Architect. My goal is to provide high quality but simple to understand Java tutorials and examples for free. If you like my website, follow me on Facebook and Twitter.

Add Comment

Your email address will not be published. Required fields are marked *

Online Shopping