Copy Elements of ArrayList to Java Vector
import java.util.ArrayList;
import java.util.Collections;
import java.util.Vector;
public class Main {
public static void main(String[] args) {
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("1");
arrayList.add("2");
arrayList.add("3");
arrayList.add("4");
arrayList.add("5");
Vector<String> v = new Vector<String>();
v.add("A");
v.add("B");
v.add("D");
v.add("E");
v.add("F");
v.add("G");
v.add("H");
System.out.println(v);
Collections.copy(v, arrayList);
System.out.println(v);
}
}
/*
[A, B, D, E, F, G, H]
[1, 2, 3, 4, 5, G, H]
*/
Related examples in the same category