Mega Code Archive

 
Categories / Java Tutorial / Collections
 

Copy Elements of One Vector to Another Vector with Collection copy

import java.util.Collections; import java.util.Vector; public class Main {   public static void main(String[] args) {     Vector<String> v1 = new Vector<String>();     v1.add("1");     v1.add("2");     v1.add("3");     Vector<String> v2 = new Vector<String>();     v2.add("One");     v2.add("Two");     v2.add("Three");     v2.add("Four");     v2.add("Five");     System.out.println(v2);     Collections.copy(v2, v1);     System.out.println(v2);   } } /*[One, Two, Three, Four, Five] [1, 2, 3, Four, Five] */