Tuesday, November 23, 2010

CoolTuts - Java - Arrays

An array is a group of variables that share the same name and are ordered sequentially from zero to one less than the number of variables in the array. The number of variables that can be stored in an array is called the array's dimension. Each element in the array is called an element of an array.

Declaring Arrays
When you declare an array variable you suffix the type with [] to indicate that this variable is an array.
Example: int [] k;

Allocating Arrays
When we create an array we need to tell the compiler how many elements will be stored in it. The numbers in the bracket specify the dimension of the array.

Initialising Arrays
Individual elements of the array are referenced by the array name and by integer which represents the position in the array. The number we use to identify them is called subscripts or indexes in a array. Subscripts are consecutive integers beginning with 0.

No comments:

Post a Comment