1. Size
Array is fixed size datastructure where ArrayList is dynamic size datastructure. We need to provide size of Array during creation of Array Object, Where ArrayList no need to provide size of it.
2. Data Types
Array can contain primitive(ie int, float, etc.) as well as Object of class based on definiition of Array. ArrayList only supports Objects, We can not store primitive datatypes in ArrayList. To store primitive data in ArrayList one needs to use wrapper class of the same.
3. Performance
4. Iterating the Value
We can iterate ArrayList using Iterator Object or with for loop. We can iterate Array using for loop.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
/*---ArrayList Iteration ---*/ /*--- Iteration using ListIterator---*/ ListIterator<User> listIterator=userListObj.listIterator(); while(listIterator.hasNext()){ User userObj=listIterator.next(); } /*--- Iteration using for-each loop---*/ for(User userObj : userListObj){ } /*--- Iteration using for loop---*/ for(int i=0;i<userAgeList.size();i++){ User userObj=userListObj.get(i); } /*---Array Iteration ---*/ /*---Iteration using for-each loop ---*/ for(User user : userArray){ } /*--- Iteration using for loop---*/ for(int i=0;i<userArray.length;i++){ User userObj=userArray[i]; } |