Anonymous Array
In java it is perfectly legal to create an anonymous array using
the following syntax.
new <type>[] { <list of values>};
Anonymous array example
new int[]{1,2,3};
The above given example creates a nameless array and initializes
it. Here, neither name of the array nor the size is specified. It
also creates a array which can be assigned to reference or can be
passed as a parameter to any method.
Anonymous array program
public AnonymousArrayExample{
public static void main(String args[]){
System.out.println(“Length of array is “ + findLength(new
int[]{1,2,3}));
}
public static findLength(int[] array){
return array.lentgh;
}
}
The above given program will print the length of the anonymous
array which is being passed to the static method.
|