View RSS Feed

Java Array

Array Variables

Rate this Entry
by , 03-04-2012 at 10:12 AM (561 Views)
Reference to object is being held by the array type variable. Declaration of a variable of array type doesnít allocate space for the array components or create the array object. But, declaratorís initializer part may make an array and a reference which will become variableís initial value.

Array length is not considered as a part of its type therefore an array typeís single variable might possess reference to other array of varying length.

Given below are few examples regarding those declarations (of array variables) which donít create array:

Java Code:
int[] ai;		// array of int
short[][] as;		// array of array of short
Object[]    ao,		// array of Object
otherAo;	// array of Object
short	s,		// scalar short 
aas[][];	// array of array of short
Here you can see few examples of declarations (of array variables) which are involved in creating the array objects:

Java Code:
Exception ae[] = new Exception[3]; 
Object aao[][] = new Exception[2][3];
int[] factorial = { 1, 1, 2, 6, 24, 120, 720, 5040 };
char ac[] = { 'n', 'o', 't', ' ', 'a', ' ', 'S', 't', 'r', 'i', 'n', 'g' }; 
String[] aas = { "array", "of", "String", };
The [] might seem for a particular variable to be a part of declaration or type in beginning of declaration, or both as it is given in this example

Java Code:
byte[] rowvector, colvector, matrix[];
This declaration is equivalent to:

Java Code:
byte rowvector[], colvector[], matrix[][];
Length of an array object never gets changed once it has been created

Submit "Array Variables" to Facebook Submit "Array Variables" to Digg Submit "Array Variables" to del.icio.us Submit "Array Variables" to StumbleUpon Submit "Array Variables" to Google

Categories
Arrays

Comments