Interview Questions

Difference between Array and ArrayList

Array:
An array is an object used to store a collection of elements of same type. The length of array is fixed and should be defined while initializing the array.

For example, Integer[] in = new Integer[10];

Array List:
An Array List is an object used to store a collection of elements (objects), whose size is expandable.

Array List is a part of java.util.Collection framework, which implements java.util.Collection interface.

Prior to java 1.5 , an Array List can store objects of any type. With the introduction of generics in Java 1.5 , an Array List can store objects of same type, by creating an Array List as follows,

List strLst = new ArrayList();

When an Array List is created without specifying capacity, the default capacity is 10.
Array Lists are actually made up of Arrays, the actual fact behind growable Array List is that, whenever a request is made to store an element exceeding its current capacity, a new Array is created in the background with additional capacity and the elements from old array are copied to it.

Since Array List is a part of Collection framework, it provides convenience methods to get, add, remove and sort the elements in the list.