What is it?

A dynamic array resizes itself automatically when it runs out of capacity and new elements need to be added to it. In Java, the ArrayList class is one such example. The official Java documentation states:

/**
* As elements are added to an ArrayList, its capacity grows automatically.
* The details of the growth policy are not specified beyond the fact that 
* adding an element has constant amortized time cost.
*
*/

Note that a dynamic array only resizes itself to grow bigger, but not smaller. The claim is that the amortized cost of inserting n elements in a dynamic array is O(1) or constant time.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.