1. Size

Array is fixed size datastructure where ArrayList is dynamic size datastructure. We need to provide size of Array during creation of Array Object, Where ArrayList no need to provide size of it.

String [] userArray= new String [10]; ArrayList userListObj=new ArrayList();

2. Data Types

Array can contain primitive(ie int, float, etc.) as well as Object of class based on definiition of Array. ArrayList only supports Objects, We can not store primitive datatypes in ArrayList. To store primitive data in ArrayList one needs to use wrapper class of the same.

int [] userAgeArray= new int[10]; User [] userArray= new User [10]; ArrayList userAgeList=new ArrayList(); ArrayList userListObj=new ArrayList();

3. Performance

Element Retrieval Operation: Both have same time complexity O(1) to retrieve the element.

Adding a new Element Operation: ArrayList having slow performance if we have large amount of elements. ArrayList internally uses Array to store the elements, When it reaches its maximum size then Array Resizing operation happens which creates new Array Object with increased size and copy all elements of previous Array to new Array Object.

4. Iterating the Value

We can iterate ArrayList using Iterator Object or with for loop. We can iterate Array using for loop.

Leave a Reply

Your email address will not be published. Required fields are marked *