ArrayList: addAll(int index, Collection c) : ArrayList « java.util « Java by API






ArrayList: addAll(int index, Collection c)

 


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("5");

    // insert all elements of Vector to ArrayList at index 1
    arrayList.addAll(1, v);
    
    for (String str: arrayList)
      System.out.println(str);
  }
}

   
  








Related examples in the same category

1.new ArrayList < E > ()
2.new ArrayList(Collection c)
3.ArrayList: add(E o)
4.ArrayList: add(int index, E element)
5.ArrayList: addAll(Collection c)
6.ArrayList: clear()
7.ArrayList: contains(Object elem)
8.ArrayList: equals(Object o)
9.ArrayList: ensureCapacity(int minCapacity)
10.ArrayList: get(int index)
11.ArrayList: indexOf(Object elem)
12.ArrayList: isEmpty()
13.ArrayList: iterator()
14.ArrayList: lastIndexOf(Object o)
15.ArrayList: listIterator()
16.ArrayList: remove(int index)
17.ArrayList: remove(Object o)
18.ArrayList: removeAll(Collection c)
19.ArrayList: retainAll(Collection c)
20.ArrayList: set(int index, T element)
21.ArrayList: size()
22.AbstractList: subList(int fromIndex, int toIndex)
23.ArrayList: toArray()
24.ArrayList: toArray(T[] a)
25.ArrayList: trimToSize()
26.for each loop for ArrayList