When we think about a small piece of data, we always use a variable to store it. Let’s go to a step further, what if we need to store large dataset, for that purpose, we also have the concept of Array. We can precisely say, an array is used to hold large dataset of the same type having random access capability.
But the downside of the array approach is that it limits the flexibility of handling the data, one of them is the size of the array which cannot be changed at runtime. It means we cannot expand or shrink the size of an array at the time of program execution, as a result, the probability of memory wastage or insufficient memory allocation can occur. So, we should know the size in advance to confront the size issue. The second disadvantage is that it can only store homogeneous dataset, which is again a problem. This demerit raises the issue of the inability to hold different types of data.
And the last one, the array is not based on some specific standardized data structure, such as Stack, List, this is why there are no inbuilt methods for sorting, searching and more. For each functionality, one requires to write the entire code i.e sorting, searching and so on.
To overcome these problems we use collections which sees a collection of objects as a single entity.
These advantages are:
This post was last modified on June 20, 2020