Professional Documents
Culture Documents
Arrays: CC3 Week 1-3
Arrays: CC3 Week 1-3
Arrays: CC3 Week 1-3
data-type [] <array-name>;
- data-type – specifies what type of data the array can hold.
Arrays do not support multiple data-types.
- array-name – specifies the array’s name using the naming
rules for identifiers.
- [] – empty pair of square brackets differentiates an array
declaration from a normal variable declaration.
Syntax
or
// Alternative syntax
dataType age[][] = new dataType[10][5];
Example
age[0] = 12;
age[1] = 56;
age[2] = 24;
age[3] = 75;
age[4] = 34;
The length field contains the number of
elements in an array.
age[0] = 12;
age[1] = 56;
age[2] = 24;
age[3] = 75;
age[4] = 34;