Java Example Programs – Add list elements to Vector


Hello, in this post we will learn about vector. How we can add list elements into an existing vector.

First of all, what is a vector in java?

we can call it a dynamic array. it’s similar to an ArrayList but it has two big advantages

  1. Vector is synchronized
  2. Vector has a lot of legacy method that is not available in the collections framework.

Vector is really useful when you don’t know the actual size of an array and you need only one array and it will increase your size when the program is running.

In this example we add few elements into our vector first then we create an ArrayList then we will add this ArrayList also into our vector. let’s check in our code.

Sample Output :

add list element into a vector

Vector has a lot of legacy methods. you can read and learn more about vector: CLICK HERE

Thanks for reading this post.

Leave a Reply

Notify of