O'Reilly logo

Java Quick Syntax Reference by Mikael Olsson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 6

image

Arrays

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required