Anonymous arrays are similar to anonymous classes in Java. Both don't have a name, so called anonymous. If you need to create an array to use only once, then you can create an anoymous array without assigning it to any variable.
Syntax: new int[] ( 15, 32, 20)
Just define the array needed followed by the keyword new. No need to specify a size, as you are assigning values to the array immediately.
For example, you need to pass an array to a function, and you don't use it anywhere else then you can do as following.
Ex: void fun( grade, new String[] ("Pass", "Fail") )
Java Search Engine
Thursday, January 17, 2008
Anonymous arrays in Java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment