Anonymous Array in Java
An array without a name is known as an anonymous array in java.
As the array doesn’t have any name so it very well may be utilized just once.
The anonymous array is passed as a contention of technique.
The anonymous array is made and initialized in a similar line.
How to Create Anonymous Array in Java?
An example program is given beneath which shows that how 1D and 2D anonymous array can be made and utilized in java.
In this program, I have quite recently made, initialized and passed two anonymous arrays in a strategy. In print() technique I am printing the components of the arrays.
In the event that you find any trouble to comprehend the program, at that point you can remark beneath and ask your questions.
class AnonymousArray
{
static void print(int a[])
{
for(int i=0;i<a.length;++i)
System.out.print(a[i]+" ");
}
static void print(int a[][])
{
for(int i=0;i<a.length;++i)
{
for(int j=0;j<a[i].length;++j)
System.out.print(a[i][j]+" ");
System.out.println("");
}
}
public static void main(String...s)
{
//1d anonymous array
print(new int[]{10,20,30,40});
System.out.println("n");
//2d anonymous array
print(new int[][]{{10,20},{30,40},{50,60}});
}
}
Output