The Array and ArrayList class looks same. but they are different in many aspects. so i have listed out some of the differences between these two. Look at the following table.
Array | ArrayList | |
1 | Array stores the values in indexed format. It is primitive data structure. | ArrayList is re – sizable array. It is a collection and stores values as an object. |
2 | Array is fixed size and can’t grow dynamically. | ArrayList is variable size and can grow or shrink dynamically. |
3 | Array is used for homogeneous data. | ArraList is used for heterogeneous data. |
4 | Example: Int[] arr = new int[5]; for(int i=0;i<5;i++) arr[i]=i+1; | Example: ArraList<int> list = new ArrayList<int>(); for(int i=0;i<5;i++) list.add(i+1); |
5 | Array can have multi dimensional. | ArrayList only be a single dimensional. |
6 | Arrays are faster for calculation. | ArraLists are faster for inserting elements. |
7 | Array is less flexible. | ArrayList is much flexible than Array. |
Related Articles:
Difference between static class loading and dynamic class loading in java
Difference between Abstract Class and Interface in Java
Difference between String and StringBuffer/StringBuilder in Java
Difference between HashMap and HashTable in Java
Difference between Csharp and Java
Difference between ArrayList and Vector in Java
Difference between Method Overloading and Method Overriding in Java
Difference between ‘is-a’ relationship and ‘has-a’ relationship in Java
Difference between C++ and Java
Difference between static class loading and dynamic class loading in java
Difference between Abstract Class and Interface in Java
Difference between String and StringBuffer/StringBuilder in Java
Difference between HashMap and HashTable in Java
Difference between Csharp and Java
Difference between ArrayList and Vector in Java
Difference between Method Overloading and Method Overriding in Java
Difference between ‘is-a’ relationship and ‘has-a’ relationship in Java
Difference between C++ and Java