Copy Elements of Vector to Java ArrayList
import java.util.ArrayList;
import java.util.Collections;
import java.util.Vector;
public class Main {
public static void main(String[] args) {
Vector<String> v = new Vector<String>();
v.add("1");
v.add("2");
v.add("3");
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("One");
arrayList.add("Two");
arrayList.add("Three");
arrayList.add("Four");
arrayList.add("Five");
System.out.println(arrayList);
Collections.copy(arrayList, v);
System.out.println(arrayList);
}
}
/*
[One, Two, Three, Four, Five]
[1, 2, 3, Four, Five]
*/
Related examples in the same category