Copy Elements of Vector to ArrayList - Java Collection Framework

Java examples for Collection Framework:Vector

Description

Copy Elements of Vector to ArrayList

Demo Code

 
import java.util.ArrayList;
import java.util.Collections;
import java.util.Vector;
 
public class Main {
 
  public static void main(String[] args) {
    Vector v = new Vector();
   //from   w  w w.j  av a 2s.  com
    v.add("1");
    v.add("2");
    v.add("3");
   
    ArrayList arrayList = new ArrayList();
   
    arrayList.add("One");
    arrayList.add("Two");
    arrayList.add("Three");
    arrayList.add("Four");
    arrayList.add("Five");
   
    System.out.println("Before copy ArrayList Contains : " + arrayList);
   
    Collections.copy(arrayList,v);
   
    System.out.println("After Copy ArrayList Contains : " + arrayList);  
  }
}

Result


Related Tutorials