Difference between Arrays and Collection in Java

Java 8Object Oriented ProgrammingProgramming

In order to store multiple values or objects of the same type, Java provides two types of data structures namely Array and Collection.

The following are the important differences between Arrays and Collection.

Sr. No.KeyArraysCollection
1SizeArrays are fixed in size i.e once the array with the specific size is declared then we can't alter its size afterward.The collection is dynamic in size i.e based on requirement size could be get altered even after its declaration.
2Memory ConsumptionArrays due to fast execution consumes more memory and has better performance.Collections, on the other hand, consume less memory but also have low performance as compared to Arrays.
3Data typeArrays can hold the only the same type of data in its collection i.e only homogeneous data types elements are allowed in case of arrays.Collection, on the other hand, can hold both homogeneous and heterogeneous elements.
4Primitives storageArrays can hold both object and primitive type data.On the other hand, collection can hold only object types but not the primitive type of data.
5PerformanceArrays due to its storage and internal implementation better in performance.Collection on the other hand with respect to performance is not recommended to use.
Published on 17-Sep-2019 10:34:05