which is used for adding all the elements of collection.
public boolean addAll(int index , Object element);
import java.util.ArrayList;
import java.util.Collections;
public class Details {
public static void main(String args[]) {
ArrayList<String> arrlist = getArrayList();
}
public static ArrayList<String> getArrayList(){
// first Array
ArrayList<String> firstArr = new ArrayList<String>();
firstArr.add("Item8");
firstArr.add("Item3");
firstArr.add("Item5");
firstArr.add("Item6");
System.out.println("First Array list : "+firstArr);
//second array
ArrayList<String> secondArr = new ArrayList<String>();
secondArr.add("Item1");
secondArr.add("Item2");
secondArr.add("Item3");
secondArr.add("Item4");
System.out.println("Sscond Array list : "+secondArr);
firstArr.addAll(2, secondArr);
System.out.println("Insert collection to specific position in Array :\n "+firstArr);
return firstArr;
}
}
//result
First Array list : [Item8, Item3, Item5, Item6]
Sscond Array list : [Item1, Item2, Item3, Item4]
Insert collection to specific position in Array :
[Item8, Item3, Item1, Item2, Item3, Item4, Item5, Item6]
EmoticonEmoticon