How to create an Array in java?

After you have declared an array variable, you can define an array that it references:

myIntArray = new int[10];        // Define an array of 10 integers 

 

This statement creates an array that stores 10 values of type int and stores a reference to the array in the variable myIntArray.

 

The reference is simply where the array is in memory.

 

You could also declare the array variable and define the array of type int to hold 10 integers with a single statement.

 

int[] myIntArray = new int[10];            //An array of 10 integers 

 

The first part of the definition specifies the type of the array. The element type name, int in this case, is followed by an empty pair of square brackets.

 

The part of the statement that follows the equal sign defines the array.

 

The keyword new indicates that you are allocating new memory for the array, and int[10] specifies that the capacity is 10 variables of type int in the array.