- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Articles
- 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?
- How to create a shallow copy of ArrayList in C#?
- Copy the elements of collection over a range of elements in ArrayList in C#
- Java Program to append all elements of other Collection to ArrayList
- Add elements to a Vector in Java
- Java Program to Remove duplicate elements from ArrayList
- Append all elements of other Collection to ArrayList in Java
- How to get first and last elements from ArrayList in Java?
- Copy all elements of Java HashSet to an Object Array
- Copy all elements of Java LinkedHashSet to an Object Array
- How to replace one vector elements with another vector elements in R?
- Java Program to Find Common Elements in Two ArrayList

Advertisements