Skip to content

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

Leave a Reply

Your email address will not be published.