

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to copy elements of ArrayList to Java Vector
In order to copy elements of ArrayList to Java Vector, we use the Collections.copy() method. It is used to copy all elements of a collection into another.
Declaration −The java.util.Collections.copy() method is declared as follows −
public static <T> void copy(List<? super T> dest,List<? extends T> src)
where src is the source list object and dest is the destination list object
Let us see a program to copy elements of ArrayList to Java Vector −
Example
import java.util.*; public class Example { public static void main (String[] args) { List<String> zoo = new ArrayList<String>(); zoo.add("Zebra"); zoo.add("Lion"); zoo.add("Tiger"); Vector vect = new Vector(); vect.add(1); vect.add(2); vect.add(3); Collections.copy(vect,zoo); // copying the ArrayList to the Vector System.out.println(vect); } }
Output
[Zebra, Lion, Tiger]
- Related Questions & Answers
- Copy Elements of One ArrayList to Another ArrayList with Java Collections Class
- Copy all elements of ArrayList to an Object Array in Java
- How to copy or clone a Java ArrayList?
- How to remove all elements of ArrayList in Java?
- Copy the elements of collection over a range of elements in ArrayList in C#
- How to create a shallow copy of ArrayList in C#?
- Differences between ArrayList and Vector in Java
- Difference Between ArrayList and Vector in Java
- Java Program to append all elements of other Collection to ArrayList
- Shuffle elements of ArrayList with Java Collections
- Swap elements of ArrayList with Java collections
- Append all elements of other Collection to ArrayList in Java
- Add elements to a Vector in Java
- Copy all elements of Java HashSet to an Object Array
- Copy all elements of Java LinkedHashSet to an Object Array
Advertisements