1.

What is the difference between Array and Collection in java?

Answer»

Array and Collection are equivalent in terms of STORING object references and manipulating data, but they differ in a number of ways. The following are the primary distinctions between an array and a Collection:

ArrayCollection
Arrays have a SET size, which means that once we build one, we can't change it to meet our needs.Collection are naturally grow-able and can be customized to meet our needs. We can change its size as per our requirement.
When it comes to performance, Arrays are the preferred to Collection.Considering performance, Collection are not preferred to Arrays.
Only homogeneous data type elements can be stored in arrays.Both homogeneous and heterogeneous components can be stored in a collection.
Because arrays have no underlying data STRUCTURE, there is no ready-made METHOD support.Any collection class is built on a standard data structure, and so there is ready-made method support for every demand as a performance. These methods can be used directly, and we are not RESPONSIBLE for their implementation.
Objects and primitives can both be stored in arrays.Only object types can be stored in a collection.
When it comes to memory, Arrays are not preferred to Collection.Considering memory, Collection are preferred to Arrays.


Discussion

No Comment Found