by Dinesh Thakur Category: array

In Java arrays have a fixed length that is specified during initialization, and determines the number of its elements. Once we set the length of the array is not possible to change it.

Declaring an array
Arrays in Java declare as follows:

int[] myArray;

Here the variable myArray is the name of the array, which is of type (int []) ie We declare an array of integers. With [] indicates that the variable that will declare an array rather than a single element.
In return the name of the variable which is of type array is a reference (reference), which points to null, as it is not yet memory allocated for the array elements.
Here is how a variable of type array that is declared, but has not allocate memory for array elements:

Creation (allocation) array - operator new

In Java, an array is created with the keyword new, which serves to allocate (allocating) memory:

int[] myArray = new int[6];

In the example, allocate an array of size 6 elements of an integer. this means that dynamic memory (heap) dedicates a section of 6-then consecutive integers. Elements of arrays are always stored in dynamic memory (in the so-called heap).

To allocate array in brackets set the number of its elements (nonnegative integer) and so its length is fixed. The type of elements to write after new, to indicate which type elements must allocate memory. Array already set length may change i.e. Arrays are fixed length.

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles