How to copy vector to array?

We can copy all elements of a vector object to an array. By passing an array object to copyInto() method, We can copy content of a vector object to an array.

package test;

import java.util.Vector;
 
public class VectorToArray {
 
    public static void main(String a[]){
        Vector<String> vct = new Vector<String>();
        //adding elements to the end
        vct.add("Selenium");
        vct.add("Java");
        vct.add("UFT");
        vct.add("Other");
        System.out.println("Actual vector:"+vct);
        String[] copyArr = new String[vct.size()];
        vct.copyInto(copyArr);
        System.out.println("Copied Array content:");
        for(String str:copyArr){
            System.out.println(str);
        }
    }
}

Output:

Actual vector:[Selenium, Java, UFT, Other]
Copied Array content:
Selenium
Java
UFT
Other

The only business I know is learning new technology and spreading the knowledge. I believe sharing is learning. This is my prime reason to build this site.
I welcome and value your comments, suggestions and corrections.

228total visits,1visits today

The only business I know is learning new technology and spreading the knowledge. I believe sharing is learning. This is my prime reason to build this site. I welcome and value your comments, suggestions and corrections.