Approach 1: (Using Vector Constructor)
- Create an ArrayList.
- Add elements in ArrayList.
- Create a vector and pass the ArrayList in Vetor Constructor.
Vector(Collection c): Creates a vector that contains the elements of collection c.
Vector<E> v = new Vector<E>(Collection c);
ArrayList : [10, 20, 30, 40, 50] Vector : [10, 20, 30, 40, 50]
Approach 2: (Using for loop)
- Create a ArrayList.
- Add some values in ArrayList.
- Create an Vector.
- Execute a loop.
- Traverse each element of ArrayList from the left side to the right side.
- Add the ArrayList elements in Vector.
ArrayList : [A, B, C, D, E] vector : [A, B, C, D, E]
Approach 3: (Using addAll() method)
This method is used to append all the elements from the collection passed as a parameter to this function to the end of a vector keeping in mind the order of return by the collection’s iterator.
boolean addAll(Collection C)
Parameters: The method accepts a mandatory parameter C which is a collection of ArrayList. It is the collection whose elements are needed to be appended at the end of the vector.
Return Value: The method returns True if at least one action of append is performed, else False.
Vector contains: [Geeks, for, Geeks]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.