ArrayList class in Java

The java.util.ArrayList class provides resizable-array and implements the List interface. Following 
are the important points about ArrayList:


  • It implements all optional list operations and it also permits all elements, includes null.
  • It provides methods to manipulate the size of the array that is used internally to store the list.
  • The constant factor is low compared to that for the LinkedList implementation.

Constructors:

S.N. Constructor & Description
ArrayList()
This constructor is used to create an empty list with an initial capacity sufficient to hold 10 elements.
ArrayList(Collection c)
This constructor is used to create a list containing the elements of the specified collection.
ArrayList(int initialCapacity)
This constructor is used to create an empty list with an initial capacity.

Methods:

S.N. Constructor & Description
void add(int index, E element)
This method inserts the specified element at the specified position in this list.
boolean addALL(Collection<? extends E> c)
This method appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collections Iterator.
void clear()
This method removes all of the elements from this list.
boolean contains(Object o)
This method returns true if this list contains the specified element.
E get(int index)
This method returns the element at the specified position in this list.
int indexOf(Object o)
This method returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
boolean isEmpty
This method returns true if this list contains no elements.