Array Initializers
by , 03-04-2012 at 10:14 AM (319 Views)
In a declaration, an array initialize might be specified. It also might be specified as an array creation expression part, that gives certain initial values and creates an array.
ArrayInitializer:
{ VariableInitializersopt ,opt }
VariableInitializers:
VariableInitializer
VariableInitializers , VariableInitializer
To make it further clear:
VariableInitializer:
Expression
ArrayInitializer
For writing array initialize, list of expressions are separated by commas and enclosed by "{" and "}".
The constructed array length would be equal to the no. of expressions.
An array initializer’s expressions get executed starting from left towards right, in textual order which occurs in source code. Value of n-1st array component is specified by the nth variable initializer. With component type of an array, every expression shall be assignment compatible. In case component type is array type itself then array initializers might be nested. After array initializer’s last expression, a trailing comma might come which is ignored.
prints:Java Code:For example: class Test { public static void main(String[] args) { int ia[][] = { {1, 2}, null }; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) System.out.println(ia[i][j]); } }
1
2









Email Blog Entry
Size Reduced for Images in PDF &...
05-15-2013, 05:53 PM in Java Software