Online Java Compiler By
JavaTpoint.com
import java.util.*; public class VectorToArrayExample3 { public static void main(String arg[]) { //Creating empty vector object Vector
v1 = new Vector
(); //Creating an array with an intial capacity of 5 Integer[] arr = new Integer[5]; //Adding elemnts to an array v1.add(10); v1.add(30); v1.add(20); v1.add(40); //Adding all the elements from v1 to v2 starting at index 1. v1.toArray(arr); //Displaying the result System.out.println("The elements are:"); for(Object obj : arr) System.out.println(obj); } }
Output