Arrays

Quick Reference Technical :

  • Initialize single dimensional and Multi-dimensional array and printing it

Limitations of Array :

  • Arrays are fixed in size.
  • Arrays can hold only homogeneous data elements. (We can use object to fix it but unlike collection you cannot say that a particular type of data will be stored in it)
  • Arrays are not implemented based on standard data structure hence ready-made method support is not present.

When to choose Arrays over collections

  • When the size of the data is known well in advance.
  • To make a collection grow-able a lot of processor time is wasted.
ArraysCollections
1. Fixed in size1. Grow-able in nature
2. Memory wastage is more2. Memory wastage is less
3. Best in performance wise3. Not better than Arrays
4. Only homogeneous datatype can he held4. Can hold heterogeneous datatype
5. No underlying data-structure hence no ready-made method support5. Implemented on basis of some data structure
6. Can hold primitive and non primitive data type6. Can hold only non primitive data-type

Details on Arrays

  • If we want to store 1000 records in a program, we cannot write 1000 variables in the program because it is a headache writing so much and secondly the readability of the program goes down. We have to use array in this case.
  • We can create an array of primitive data type and objects as well.
  • We need to know the size of data in advance to use array list.
  • Always best to use Arrays if the size of data is fixed and known in advance i.e compile time.

Leave a Comment