Copy Elements of Vector to Java ArrayList Last Updated : 15 Nov, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Since Vector class and ArrayList class both are part of Java Collections, ie Collection framework, so both of these classes can use methods available to the Collection framework. Copy() method is one of the methods of Collection Interface which is used to copy one list to another list, here list can be any collection like ArrayList, LinkedList, and Vector. One important point to remember is that if the destination list length is greater than the length of the source list that is to copy, then the other element will remain unaffected, ie if the length of the destination list is 4 and the length of the source list is 3, then 3 elements of destination list would be replaced by elements of source list, but the 4th element, ie at index 3 would remain unaffected in the destination list. Ways To copy elements of the Vector to ArrayList Passing in the constructorAdding one by one using add() method Method 1: Passing in the constructor In this approach, we will simply pass the one Vector into the other List’s constructor.By using this approach if we change in first vector values then it will not change the values of the List.This is the easiest way to copy elements of the vector to Java ArrayList. Java // Java Program for copying Vector to List // by passing in the constructor import java.io.*; import java.util.*; class GFG { public static void main(String[] args) { // creation of Vector of Integers Vector<Integer> gfg = new Vector<>(); // adding elements to first Vector gfg.add(11); gfg.add(22); gfg.add(24); gfg.add(39); // passing in the constructor of List List<Integer> gfg2 = new ArrayList<>(gfg); // Iterating over second Vector System.out.println( "-----Iterating over the List----"); for (Integer value : gfg2) { System.out.println(value); } } } Output-----Iterating over the List---- 11 22 24 39 Method 2: Adding one by one using add() method In this approach, we will iterate over each element of Vector and add that element to the List.Here if you change the Vector element then it will not change the elements of the List.It is not the best approach, but it’s a simple iteration process. Java // Java Program for copying one Vector to the List // by adding elements one by one using add() method import java.io.*; import java.util.*; class GFG { public static void main(String[] args) { // creation of Vector of Integers Vector<Integer> gfg = new Vector<>(); // adding elements to first Vector gfg.add(50); gfg.add(24); gfg.add(95); gfg.add(31); List<Integer> gfg2 = new ArrayList<>(); for (Integer value : gfg) { gfg2.add(value); } // Iterating over List System.out.println( "-----Iterating over the List----"); for (Integer value : gfg2) { System.out.println(value); } } } Output-----Iterating over the List---- 50 24 95 31 Comment More infoAdvertise with us Next Article Java Program to Copy Elements of ArrayList to Vector L lavishgarg26 Follow Improve Article Tags : Java Java Programs Java-Collections Java-ArrayList Java-Vector +1 More Practice Tags : JavaJava-Collections Similar Reads Java Program to Copy Elements of ArrayList to Vector Vector implements List Interface, like ArrayList it also maintains insertion order but it is rarely used in the non-thread environment as it is synchronized, and due to which it gives a poor performance in adding, searching, deleting, and updating of its elements. To copy elements from one collectio 4 min read Convert ArrayList to Vector in Java There are several ways to convert ArrayList to Vector. We can use a vector constructor for converting ArrayList to vector. We can read ArrayList elements one by one and add them in vector. Approach 1: (Using Vector Constructor) Create an ArrayList.Add elements in ArrayList.Create a vector and pass t 3 min read Copy Elements of One Java Vector to Another Vector in Java Vector is similar to arrays but is growable also, or we can say no fixed size is required. Previously vector was a part of legacy classes but now it is part of Collections. It also implements a List interface, so we can use any method of list interface on vectors also. Syntax : Vector<Integer> 3 min read How to Make a Deep Copy of Java ArrayList? The Advantage of ArrayList is it can be defined without giving a predefined size. But the disadvantage is it is more expensive to create and maintain. To have the solution for these expenses we can create a deep copy of an ArrayList. There are two types of copies that can be made the first one is a 3 min read Reverse Order of All Elements of Java Vector Vector class Implements a dynamic array means it can shrink and expand its size as required just likely having the same operations like that in the arrays. Don't confuse it with ArrayList as there is a thin line between vector and ArrayList, where the vector is synchronized rest the insertion order 4 min read How to Copy and Add all List Elements to an Empty ArrayList in Java? We can copy and add List items in Array List using addAll() method. This method accepts a Collection (Ex. List) as an argument and adds the collection items at the end of its calling Collection (Ex. ArrayList). This method returns a boolean value. addAll() return true if the collection successfully 2 min read Like