import java.util.Vector; public class VectorCopyExample { public static void main(String[] args) { Vectorvector = new Vector<>(); vector.add("apple"); vector.add("banana"); vector.add("orange"); String[] array = new String[vector.size()]; vector.copyInto(array); for(String s : array) { System.out.println(s); } } }
import java.util.Vector; public class VectorCopyExample2 { public static void main(String[] args) { VectorIn this example, we create a Vector object and add some integers to it. We then create an Integer array of the same size as the Vector and use the copyInto() method to copy the elements of the Vector into this array. Finally, we iterate over the array and compute the sum of its elements. The java.util package is part of the Java standard library.vector = new Vector<>(); vector.add(10); vector.add(20); vector.add(30); Integer[] array = new Integer[vector.size()]; vector.copyInto(array); int sum = 0; for(int i : array) { sum += i; } System.out.println("Sum of array elements: " + sum); } }