Anonymous Arrays


ANONYMOUS ARRAYS

Sometimes we can declare an array without name, such type of nameless array are called anonymous arrays.
The main purpose of anonymous arrays is just for instant use(one - time usage).

Declare Anonymous Array
We can create anonymous array as follows
new int[]{10,20,30};

While creating anonymous arrays we can't specify the size otherwise we will get compile time error. .
new int[3]{1,2,3}; -- invalid

We can create multi dimensional anonymous array also.
new int[][]{{1,23,4},{2,3,4}};

Based on our requirement we can give the name for anonymous array , then it is no longer anonymous.


Comments

Popular posts from this blog

Variables (Part-1)

length vs length()

Arrays in Java