Adding elements to the Java ArrayList
1) Adding element to the end of the List
boolean add(Object element)
Adds specified element to the end of the ArrayList
2) Insert element in the middle of the ArrayList
void add(int index, Object element)
Inserts specified element into the ArrayList at given index. This
method can throw IndexOutOfBoundsException if index is out of range.
3) Append elements of a Collection to ArrayList
boolean addAll(Collection c)
Appends all elements of specified Collection in order returned by
the specified Collection’s Iterator.
4) Insert elements of a Collection to ArrayList
boolean addAll(int index, Collection c)
Inserts all elements of the specified collection into ArrayList
at given index. This method can throw IndexOutOfBoundsException
if index is out of range.
|