import java.util.Vector; public class VectorToArrayExample { public static void main(String[] args) { Vectorv = new Vector (); v.add(1); v.add(2); v.add(3); Integer[] arr = v.toArray(new Integer[0]); for (Integer i : arr) { System.out.println(i); } } }
import java.util.Vector; public class VectorToArrayExample { public static void main(String[] args) { VectorIn this example, we create a Vector of type Integer and add three elements to it. We then create a new array of type Integer with a length of 3. We pass this array to the toArray method, and the elements of the Vector are copied into this array. We then print out each element of the array. Package Library: java.utilv = new Vector (); v.add(1); v.add(2); v.add(3); Integer[] arr = new Integer[3]; v.toArray(arr); for (Integer i : arr) { System.out.println(i); } } }