Arrays are created of fix size whereas ArrayList is of not fix size. It means that once array is declared as :
- int [] intArray= new int[6];
- intArray[7] // will give ArraysOutOfBoundException.
Also the size of array cannot be incremented or decremented. But with arrayList the size is variable.
- Once the array is created elements cannot be added or deleted from it. But with 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.
- ArrayList is one dimensional but array can be multidimensional.
- To create an array the size should be known or initalized to some value. If not initialized carefully there could me memory wastage. But arrayList is all about dynamic creation and there is no wastage of memory.
No comments:
Post a Comment