Here is a Java Program to Insert all elements of other Collection to Specified Index of Java ArrayList Example
Output of Above Java Program
After inserting all elements of Vector at index 1, ArrayList contains..
1
4
5
2
3
import java.util.ArrayList; import java.util.Vector; class ArrayListExample { public static void main(String[] args) { ArrayList arrayList = new ArrayList(); arrayList.add("1"); arrayList.add("2"); arrayList.add("3"); Vector v = new Vector(); v.add("4"); v.add("5"); arrayList.addAll(1,v); System.out.println("After inserting all elements of Vector at index 1, ArrayList Content: "); for(int i=0; i<arrayList.size(); i++) System.out.println(arrayList.get(i)); } }
Output of Above Java Program
After inserting all elements of Vector at index 1, ArrayList contains..
1
4
5
2
3