Copy vector to array in java

The copyInto() method is used to copy vector to array in java.

Syntax:

vector.copyInto(copyArray);

Example:

package com.w3spoint;
 
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);
	String[] copyArray = new String[vector.size()];
	vector.copyInto(copyArray);
        System.out.println("Copied Array content:");
        for(String string:copyArray){
            System.out.println(string);
        }
  }
}

Output

Actual vector:[Jai, Mahesh, Hemant, Vishal]
Copied Array content:
Jai
Mahesh
Hemant
Vishal
Please follow and like us:
Content Protection by DMCA.com