This page topics close

Sometimes we can create an array without name also , such type of nameless array is known as Anonymous Array .

Array without having any name is called Anonymous Array.

The main object of anonymous arrays is , it is created only for instant use.

  • Syntax of creating Anonymous Array

    new DataType[ ]{values} ;

    //example of anonymous array
    class Example {
        public static void print(int a[]) {
            for (int i = 0; i < a.length; i++) {
                System.out.print(a[i] + "\t");
        public static void main(String[] args) {
            //we will pass anonymous array in print() method
            Example.print(new int[]{1, 3, 2});
    1	3	2

At the time of Anonymous array creation we can not specify the size of the array otherwise we will get Compile Time Error.

What next?

The next topic is introduction to Array

Share this page