ArrayList is a Collection class which extends AbstractList and implements List interface.
- ArrayList underlying data structure is dynamic grow-able array.
- It implements random access interface. So we can access elements from the array list randomly by using index.
- ArrayList is not synchronized. So if we are using ArrayList in multi threading we need to explicitly make ArrayList as synchronized by using Collection.synchronizedList(List l) method.
- In ArrayList we can’t be used with primitives with generic.(ArrayList a = new ArrayList<>() : It is invalid and compile time error).
- ArrayList(): Creates the object with default initial capacity. (Till Java 1.6 initial capacity is “10” but from java 1.7 initial capacity is “0” but when we add first element then capacity will be “10”).
- ArrayList(int initialCapacity): creates the object with specified capacity.
- ArrayList(Collection c): Creates the object with specified collection data.
When the capacity increased to max then the new capacity will be
int newCapacity = (oldCapacity * 3)/2;