Online Java Compiler By
JavaTpoint.com
import java.util.*; public class VectorToArrayExample2 { public static void main(String arg[]) { //Create Vector "vec" object Vector
vec = new Vector<>(); //Adding elements to vector vec.add("Java"); vec.add("Android"); vec.add("Python"); vec.add("COBOL"); System.out.println("Contents of a vector are: "); //Displaying elements of the vector for(String val: vec) { System.out.println(val); } //Create an array and copy the vector elements to it Object[] arr = vec.toArray(); //Displaying elements of the array System.out.println("Elements of the array: "); for(Object val : arr) { System.out.println(val.toString()); } } }
Output