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

Java examples for Collection Framework:Vector

Description

Insert all elements of other Collection to Specified Index of Vector

Demo Code

 
import java.util.ArrayList;
import java.util.Vector;
 
public class Main {
 
  public static void main(String[] args) {
    Vector v = new Vector();
   /*from   w  ww.  j  ava  2  s . c  om*/
    v.add("1");
    v.add("2");
    v.add("3");
   
    ArrayList arrayList = new ArrayList();
    arrayList.add("4");
    arrayList.add("5");
   
    v.addAll(1,arrayList);
   
    System.out.println("After inserting all elements of ArrayList at index 1, Vector contains..");
    for(int i=0; i<v.size(); i++)
      System.out.println(v.get(i));
  }
}

Result


Related Tutorials