An array is a data structure used for storing a collection of values.

Array declaration

To declare an array, a set of square brackets is appended to the data type the array will contain, followed by the array’s name. Alternatively, the brackets may be placed after the array name. Arrays can be declared with any data type and all of its elements must then be of that type.

int[] x;int y[];

Array allocation

The array is allocated with the new keyword, followed again by the data type and a set of square brackets containing the length of the array. This is the fixed number of elements that the array can contain. Once the array is ...

Get Java Quick Syntax Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.