Java List insert all elements from other Collection by index

Description

Java List insert all elements from other Collection by index



import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class Main {
  public static void main(String[] args) {
    List<String> arrayList = new ArrayList<String>();
    arrayList.add("CSS");
    arrayList.add("HTML");
    arrayList.add("Java");
    System.out.println(arrayList);

    Vector<String> v = new Vector<String>();
    v.add("SQL");
    v.add("MySQL");
    System.out.println(v);// www .  ja v  a 2 s.  com

    // insert all elements of Vector to ArrayList at index 1
    arrayList.addAll(1, v);

    System.out.println(arrayList);
  }
}



PreviousNext

Related