Programming |
Array |
Collection |
Arrays are fixed in size.
|
Collections are growable in nature.
|
Arrays can contain only homogeneous element types. |
Collections can contain both homogeneous and heterogeneous elements. |
The size of the Array needs to be declared at the time of creation. int[] intArr= new int[10]. Here the size of the integer array is 10. |
There is no need to declare the size at the time of creation. We can do that but there is no need. List list = new ArrayList(); |
Both primitives and object data types can be stored into an Array. |
A collection is only meant for object data types. It cannot store primitives. |
To access the element in Array only index notation can be used. |
You can use Iterator or various method to access the elements from Collections. |
java.util.Arrays class can be used to perform operations like searching, sorting, etc on Arrays. |
Similarly, java.util.Collections class can be used to manipulate Collection object. |
Arrays are faster and should be preferred when the number of elements to be added to Array is known at the beginning. |
When the number of elements is not known then Collection should be used. |
Arrays don't provide readymade method support because there is no underlying data structure |
Collections are implemented based on some data structure which provide us with a wide variety of readymade method support. |