import java.util.ArrayList; import java.util.Vector; public class VectorExample { public static void main(String[] args) { ArrayListlist = new ArrayList<>(); list.add("apple"); list.add("banana"); list.add("cherry"); Vector vector = new Vector<>(); vector.addAll(list); System.out.println(vector); } }
import java.util.HashSet; import java.util.Vector; public class VectorExample { public static void main(String[] args) { HashSetIn this example, we create a HashSet of integers and add three elements to it. We then create a new Vector and use the addAll method to add all of the elements from the HashSet to the Vector. Finally, we print out the contents of the Vector, which should be [1, 2, 3]. The java.util Vector addAll method is part of the Java Collection Framework and is located in the java.util package.set = new HashSet<>(); set.add(1); set.add(2); set.add(3); Vector vector = new Vector<>(); vector.addAll(set); System.out.println(vector); } }