Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
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.
This brings us end of Java Array Tutorial. Please let us know your views by leaving a comment in comments section.
<< Multidimensional Array Example

public class Anonymous{
thanks i dont know this till
good explanation
please wirte next time good
It should be "array.length;"
Post new comment