Java Programming
About Lesson

An Array is a fixed length data structure that stores multiple data elements of same data type.  All the elements of an array share the same name, and they are distinguished from one another with the help of an index.

Arrays are supported directly by the Java programming language but there is no array class.  The length of an array is established when the array is created (at runtime).  After creation, an array is a fixed-length structure.

Syntax of array declaration is as follows:

data-type arrayName [];

 

The following are some of declarations for arrays:

float[] marks;

boolean [] gender;

Object[] listOfObjects;

String[] NameOfStudents;

The declaration of array doesn’t allocate memory for it.  Array must be initialized before using.

Array size must be defined or its size must be specified to allocate required memory space for its elements.  For that new operator can be used.  The new is an operator that is used to allocate memory for the data element.

The memory size of an array is equivalent to the total size of all its elements.

Definition of array:

int arr[] = new int[5];

(or)

int arr[];

arr=new int[5];

(or)

int arr[]={1,3,5,7,9}; 

The last definition is also known as declaration with initialisation.

The initialisation of any data element is nothing but storing some values by the developer.  Any data element must be initialised before its first use. 

You cannot copy content of this page