Copy or clone a vector in java

The clone() method is used to create similar copy of vector in java.

Syntax:

Vector.clone()

Example:

package com.w3schools;
 
import java.util.Vector;
 
public class Test {
  public static void main(String args[]){
	Vector<String> vector = new Vector<String>();
        //adding elements to the end
	vector.add("Jai");
	vector.add("Mahesh");
	vector.add("Hemant");
	vector.add("Vishal");
	System.out.println("Actual vector:"+vector);
        Vector<String> copy = (Vector<String>) vector.clone();
        System.out.println("Cloned vector:"+copy);
  }
}

Output

Actual vector:[Jai, Mahesh, Hemant, Vishal]
Cloned vector:[Jai, Mahesh, Hemant, Vishal]