> array initializers java ~ Online tutorial

array initializers java

Array Initializers
An array initializer may be specified in a declaration, or as part of an array creation
expression , creating an array and providing some initial values:
ArrayInitializer:
{
VariableInitializersopt ,opt
}
VariableInitializers:
VariableInitializer
VariableInitializers , VariableInitializer

1)An array initializer  is written as a comma-separated list of expressions,
enclosed by braces “{” and “}”.
2)The length of the constructed array will equal the number of expressions.
3)The expressions in an array initializer are executed from left to right in the
textual order they occur in the source code
.4) The nth variable initializer specifies the value of the n-1st array component.
5) Each expression must be assignment-compatible with the array’s component type,
 or a compile-time error results
.6)  It is a compile-time error if the component type of the <a href="http://gan.doubleclick.net/gan_click?lid=41000613802112277&pubid=21000000000397534">array</a> being initialized is not
reifiable .
.
As an example:
class Test 
{
public static void main(String[] args)
 {
int ia[][] = { {1, 2}, null };
for (int[] ea : ia)
for (int e: ea)
System.out.println(e);
}
}
prints:
1
2

before causing a NullPointerException in trying to index the second component
of the array ia, which is a null reference.

Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: