Introduction to Array

16 Shares

Array

It is the collection of elements of a similar data type that take continues memory location. It is used to store multiple data in a singles variable.

Creations of Array: –

1) Syntax: –

<Data type><Array name > []
It is called as Array declaration. It is used to informed the compiler that array with specified name and type has to be created.

< Array name > = new < data type >[ size ]

It is called as memory allocation. It is used to provide a memory of specified size to the variable.

Example: –

Example:-

2) Syntax : –

< Data type >< Array name > [] = new < data type> [ size ]
It will create the array of specified type and allocate memory for it. It is called as array declaration and memory allocation.

Example:-

3) Syntax: –

<Data type > [] < array name > = new < data type > [size]
It will create the array of specified type and allocate memory for it. It is called as array declaration and memory allocation.

Example:-

4) Syntax :-

< Data type > [] < array name > = { elements of array };
Here [] must be provided before the array name and size be provided.

Example:-

5) Array declaration and initialization: – Array can be declared as well as initialized at the same time that is data can be provided at the same time.

BOUND CHECKING:-

Bound checking is the mechanism of monitoring the array size and does not allow to access the java array outside the range. If be try to access the elements of the array outside the range them runtime error will be generated. Java support bound checking and doesn’t allow to access the elements of the array outside the range and if try to access the data outside the range runtime error will be generated.

Example:-

 

16 Shares

Leave a Reply