Copy Java ArrayList To Java Vector Using Collection In Java
Chapter:
Collections
Last Updated:
11-06-2016 19:51:10 UTC
Program:
/* ............... START ............... */
import java.util.ArrayList;
import java.util.Collections;
import java.util.Vector;
public class JavaArrayListToVector {
public static void main(String[] args) {
ArrayList arrayList = new ArrayList();
arrayList.add("1");
arrayList.add("4");
arrayList.add("2");
arrayList.add("5");
arrayList.add("3");
// create a Vector object
Vector v = new Vector();
// Add elements to Vector
v.add("A");
v.add("B");
v.add("C");
v.add("D");
v.add("F");
v.add("G");
v.add("H");
System.out.println("Before copy: " + v);
Collections.copy(v, arrayList);
System.out.println("After Copy : " + v);
}
}
/* ............... END ............... */
Output
Output Before copy: [A, B, C, D, F, G, H] After Copy : [1, 4, 2, 5, 3, G, H]
Notes:
-
Java example shows how to copy elements of Java ArrayList to Java Vector using copy method of Collections class.
Tags
Collection,Java ArrayList To Java Vector, Java