Example & Tutorial understanding programming in easy ways.

What is difference between Arrays and ArrayList ?

What is difference between Arrays and ArrayList ?

Arrays

ArrayList

The Arrays are created of fix size.

ArrayList is of not fix size.

The size of array cannot be incremented or decremented
int [] intArray= new int[1];

intArray[2]   // will give ArraysOutOfBoundException.

 

ArrayList the size is variable.

Once the array is created its elements cannot be added or deleted from it at runtime.

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.

 

Array can be multidimensional.
int[][][] intArray= new int[1][1][1];   // 3 dimensional array    

 

ArrayList is one dimensional

To create an array the size should be known or initialized to some value.

ArrayList is all about dynamic creation we donít need any size at initialisation time.

Array initialized without caring the memory wastage.

There is no wastage of memory


Read More →