import java.util.ArrayList;Runtime:
import java.util.List;
import java.util.Vector;
public class ArrayListaddAllIndex{
public static void main(String[] args) {
// Create an ArrayList< String>
ArrayList< String> aList = new ArrayList< String> ();
//add strings to ArrayList
aList.add("1");
aList.add("2");
aList.add("3");
System.out.println("ArrayList before calling addAll(): ");
for(String e:aList)
System.out.println(e);
//Vector
List< String> vec = new Vector< String> ();
//add values to Vector
vec.add("4");
vec.add("5");
//Apple the addAll()
aList.addAll(1, vec) method;
System.out.println("ArrayList after calling addAll():");
for(String e:aList)
System.out.println(e);
}
}
ArrayList before calling addAll():To add another collection, simply replace Vector with the collection you want. For example, if you want to insert all the elements of an ArrayList into another ArrayList, replace Vector with ArrayList.
1
2
3
ArrayList after calling addAll():
1
4
5
2
3
Please disable your ad blocker and refresh the window to use this website.