
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
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]
Advertisements