# Append all elements of another Collection to a Vector in Java

Java 8Object Oriented ProgrammingProgramming

The elements of a Collection can be appended at the end of the Vector using the method java.util.Vector.addAll(). This method takes a single parameter i.e. the Collection whose elements are added to the Vector and it returns true if the Vector is changed.

A program that demonstrates this is given as follows −

## Example

Live Demo

import java.util.Vector;
public class Demo {
public static void main(String args[]) {
Vector vec1 = new Vector();
System.out.println("The Vector vec1 elements are: " + vec1);
Vector vec2 = new Vector();
System.out.println("The Vector vec2 elements are: " + vec2);
}
}

The output of the above program is as follows −

The Vector vec1 elements are: [7, 3, 5, 9, 2]
The Vector vec2 elements are: [1, 8, 6, 7, 3, 5, 9, 2]

Now let us understand the above program.

First, the Vector vec1 is defined and elements are added using the Vector.add() method. Then Vector vec1 is displayed. A code snippet which demonstrates this is as follows −

Vector vec1 = new Vector();
System.out.println("The Vector vec1 elements are: " + vec1);
Vector vec2 = new Vector();
System.out.println("The Vector vec2 elements are: " + vec2);