Header Ads

What Is The Difference Between Array And Collection In Java??

In my last two posts I have shown the concept of Array here and Collection here . In this post I am trying to differentiate between the two...

This is very important to understand the concept and difference. This will give you an idea when to use these.

Arrays are of fixed size.So after creation we can not increase or decrese it's size.Collections are growable in size.As per our need we can increase or decrease.
For memory usage Arrays are not recommended to use. For memory allocation Collections are recommended to use.Due to its growable and sinkable nature.
Since array is fixed sized hence in terms of performance Arrays are betterIn terms of performance Collections are slower
Arrays can hold homogeneous data element Collections can hold homogeneous and heterogeneous data
Arrays can hold primitives and objectsCollections can hold only objects
There is no underlying data structure available so ready made data support is not available For each Collection class there is underlying data structure so upon requirement ready made data support is available for collection
Arrays does not have methodsCollection has their inbuilt method to support operations

Powered by Blogger.