10.03. Issues with Array

Issues with Array

  • Eclipse: Oxygen
  • Java: 1.8

There are many issues with the array, such as the memory factor, where the user once assigned any memory to the array cannot add or change the memory and append any other element to it.

There are significant weaknesses when working with arrays, these includes:

  • Fixed-size (We can create a structure with a fixed number of member variables, but we can’t change that amount)
  • Expensive to move many of the entries in an array
  • All the entries of an array must be of the same type
  • You cannot traverse back to the original state and change the memory once the memory is allocated.

Let us understand with the help of an example.

Suppose we have created an array of 100 elements and allocated its size as 100 elements and we have stored only two elements in the array. Imagine how much amount of memory is wasted as soon as we allocated the size and initialized the array object. Hence, storing two elements in an array of 100 elements is a total wastage of memory. Also, memory is not cheap. So for that ArrayList is proposed where no chunk is allotted when the ArrayList is assigned but increased as the requirements increase.

Contributed by: Poonam Tomar

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
muawya
muawya
3 years ago

Please can give an example (I study in your video’s in Udemy school).
Thanks