Advanced Java Tutorial


Total available pages count: 55
Subject - Java Technologies

Array

An array is the simplest linear data structure; it is a collection of elements of the same type stored at contiguous memory locations. each data element can be randomly accessed using an index number.

Array stores a fixed number of similar elements; it can store primitive data types as well as to object.

Array declaration

datatype varname []=new datatype[size];
datatype[] varname=new datatype[size];
/*array initialization*/

array_name = new data-type [size of array];
array_name = new data-type {elements of array using commas};

 

  • It's easy to sorting & iteration
  • Allows random access
  • Replacement of multiple variable
  • The common data type of array element known as a base type
  • Indexing of variable in array get starts from 0
  • Define array before it can use it to store data
  • You can find the length of an array using member ‘length’

Limitation

  • Fixed in size
  • Found difficulty in insert & delete
  • Need contiguous memory to get allocate
  • If capacity is more and occupancy less, no of array get wasted


Comments