What is an anonymous array? Give example?
Answers
In Java, an Array without having any name is called an anonymous array. Using anonymous array we can pass an array with user values without the referenced variable. new int [][] { {40, 50}, {10, 20, 30} }; For Anonymous array creation, do not mention size in [] .
An array in Java without any name is anonymous array. It is an array just for creating and using instantly. We can create an array without name, such type of nameless arrays are called anonymous array. The main purpose of anonymous array is just for instant use (just for one time usage) .
Few examples of creating anonymous array in java: anonymous int array : new int[] { 1, 2, 3, 4}; anonymous String array : new String[] {"one", "two", "three"}; anonymous char array : new char[] {'a', 'b', 'c');