Example & Tutorial understanding programming in easy ways.

What is difference between Arrays and ArrayList ?

Following are some difference as :

                             Arrays                          ArrayList
 
1 The Arrays are created of fix size.
 
1 ArrayList is of not fix size.
 
2 The size of array cannot be incremented or decremented
int [] intArray= new int[1];
intArray[2] // will give ArraysOutOfBoundException.
2 ArrayList the size is variable.
 
3 Once the array is created its elements cannot be added or deleted from it at runtime. 3 ArrayList the elements can be added and deleted at runtime.
List list = new ArrayList();
list.add(1);
list.add(3);
list.remove(0) // will remove the element from the 1st location.
 
4 Array can be multidimensional.
int[][][] intArray= new int[1][1][1]; // 3 dimensional array
4 ArrayList is one dimensional.
 
5 To create an array the size should be known or initialized to some value.
 
5 ArrayList is all about dynamic creation we don’t need any size at initialisation time.
 
6 Array initialized without caring the memory wastage.
 
6 There is no wastage of memory.
 
7 You can not use generics on array .
 
7 ArrayList can be generics to ensure type-safety.
 
8 Array is capable to store both primitive as well as non-primitive. 8 you cannot store primitives in ArrayList.

Read More →