Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Add Elements to Java ArrayList

Add 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.


<< Java ArrayList Constructors
    Search Elements from Java ArrayList >>
Your rating: None Average: 1 (1 vote)
Share this
Anonymous's picture

addAll() can also be used to

addAll() can also be used to copy data from one array-list to another as stated here

Post new comment