Insert all elements of other Collection to Specified Index of ArrayList in Java
Description
The following code shows how to insert all elements of other Collection to Specified Index of ArrayList.
Example
/* www . java 2s .co m*/
import java.util.ArrayList;
import java.util.Vector;
public class Main {
public static void main(String[] args) {
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("1");
arrayList.add("2");
arrayList.add("3");
Vector<String> v = new Vector<String>();
v.add("4");
v.add("java2s.com");
// insert all elements of Vector to ArrayList at index 1
arrayList.addAll(1, v);
for (String str: arrayList)
System.out.println(str);
}
}
The code above generates the following result.