Tuesday, April 14, 2015

Arrays

An array is a container object that holds a fixed number of values, unlike a regular variable that can only contain a single value. 

The length of an array is established when the array is created. After creation, its length is fixed. 

Each item in an array is called an element, and each element is accessed by its numerical index.
The number corresponding to each position is called an index or a subscript.
Array indexes always begin at zero. That means the value stored at index 5 is actually the sixth value in the array.

Arrays are objects. To create an array the reference to the array must be declared.
The variable height is declared to be an array of integers whose type is written as int[].

All valuables stored in an array have the same type. An example is that you can create an array that can hold integers or an array that can hold strings but not an array that can hold both integers and strings.

Another important characteristic of arrays is that their size is held in a constant called length in the array object

One way you can declare an array is by:
int[] num = new int[7];

Here is a way you can assign value to arrays:
num[0] = 10;





No comments:

Post a Comment