Insert all elements of other Collection to Specified Index of ArrayList - Java Collection Framework

Java examples for Collection Framework:ArrayList

Description

Insert all elements of other Collection to Specified Index of ArrayList

Demo Code


import java.util.ArrayList;
import java.util.Vector;
 
public class Main {
 
  public static void main(String[] args) {
    ArrayList arrayList = new ArrayList();
   //from  w  ww . j a va  2  s .  c  om
    arrayList.add("1");
    arrayList.add("2");
    arrayList.add("3");
   
    //create a new Vector object
    Vector v = new Vector();
    v.add("4");
    v.add("5");
   
    arrayList.addAll(1,v);
   
    for(int i=0; i<arrayList.size(); i++)
      System.out.println(arrayList.get(i));
  }
}

Result


Related Tutorials