Main differences between Array and ArrayList in java

How is an array different from ArrayList ? What are the major differences between Array and ArrayList ? Why difference between Array and ArrayList is the most commonly asked Java Interview Question . Below given are the points for Array vs ArrayList which describes it.

S. No    Array    ArrayList
1Array is fixed length , thus static in natureArrayList  is dynamic in nature
2Array does not extend any class or implement interfaceArrayList implements the List Interface and internally backed by Array
3Array does not support Generics and throws ArrayStoreExceptionArrayList supports Generics and ensures type-safety.
4

Array provides length() method to calculate

the Array Length

Example:

int studentObject[] = new Integer[3];int
int studentObjectLength= studentObject.length ;

ArrayList provides size() method to calculate the ArrayList size

Example:
ArrayList studentObject = new ArrayList();
studentObject.add(101);
studentObject.add(102);
studentObject.size();

5Arrays allows to store primitive types and objectsArrayList allows to store objects only
6

Array uses assignment operator to store element into array

Example:

int[] studentId = { 101, 102,103,104,105 };

Object[] studentId = new Object[10];

ArrayList uses add() method to store element in ArrayList

Example:

ArrayList<Integer> studentIdList = new ArrayList<Integer>();
studentIdList.add(100);

7

Arrays are faster when frequent access is required.

Array operations execution time

Arrays Lookup –  O(1)

Arrays Append ( last element) – O(1)

Array Insertion – O(n)

Array Deletion – O(n)

ArrayList is faster when frequent insert and deletion is required.  Overall ArrayList takes  more time as it uses List interface as part of Collection Framework and each node in the List has its own memory when compared to Arrays.
8

Array is traversed using for loop

ArrayList is traversed using Iterator

 

Main differences between Array and ArrayList in java
Scroll to top
Copy Protected by Chetan's WP-Copyprotect.