What is an Array and difference between array and collection?

What is an Array and difference between array and collection?

What is an Array and difference between array and collection?

What is an Array and difference between array and collection?
  • An array is an index collection of fixed no of homogeneous data elements.
  • The main advantage of arrays is we can represent multiple values by using a single variable so that readability of the code will be improved.
  • Java array is an object the contains elements of a similar data type. It is a data structure where we store similar elements. We can store only fixed set of elements in a Java array.
  • Once defined, the size of an array is fixed and cannot increase to accommodate more elements. The first element of an array starts with index zero.
  • Each value stored, in an array, is known as an element and all elements are indexed. The first element added, by default, gets 0 indexes. That is, the 5th element added gets an index number of 4.
  • Elements can be retrieved by their index number.
  • Array elements are stored in contiguous (continuous) memory locations.
  • Once the array is created, its size is fixed. That is, at runtime if required, more elements cannot be added. This is another limitation of arrays compared to other data structures.
  • One array name can represent multiple values. An array is the easiest way to store a large quantity of data of same data types. For example, to store the salary of 100 employees, it is required to declare 100 variables. But with arrays, with one array name all the 100 employees salaries can be stored.
  • Arrays can be multidimensional.
  • At the time of creation itself, array size should be declared (array initialization does not require size).

Leave a Reply

Your email address will not be published. Required fields are marked *

*