dataType [] arrayName; or dataType arrayName[]; boolean [] status; int [] numPoints; double [] xPos;When you simply declare an array you have not created any space in memory for the contents of the array.
dataType [] arrayName = new dataType [ arraySize ]; char [] alphabet = new char [26];The size of an array cannot be changed after it is created. array.length gives the size of an array. The array variable points to the first element of the array. The elements of the array so far are undefined.
Another way of creating the the array is to specify all the elements of the array:
short [] numList = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
alphabet [2] = 'c';arrayName[i] will return the array element at position i provided i is in the range 0 <= i < array.length.
public static int sumArray ( int[] anArray )
{
int sum = 0;
for ( int i = 0; i < anArray.length; i++ )
sum += anArray[i];
return sum;
}
public static int[] copyArray ( int[] anArray )
{
int[] dupArray = new int [anArray.length];
for ( int i = 0; i < anArray.length; i++ )
dupArray[i] = anArray[i];
return dupArray;
}