ArrayList Class in java.util: Types of constructors, ensureCapacity method

ArrayList Class: ArrayList Class handles the dynamic array and List interface in java.util. It extends AbstractList class. ArrayList is actually an array of variable length which can be increased or decreased in size dynamically.

Types of constructors in ArrayList Class:

Type-1: To create an empty array list.

ArrayList( )

Type-2: Create an array list with elements of collection cl.

ArrayList(Collection cl)

Type-3: Create an arry list that has size.

ArrayList(int size)

ensureCapacity( ) method: It is used to increase the capacity of the array list manually.


void ensureCapacity(int cp)

where, cp is capacity.

Leave a Reply