Search code examples
javaarraysperformancedefinition

Java: int[] array vs int array[]


Is there a difference between

int[] array = new int[10];

and

int array[] = new int[10];

?

Both do work, and the result is exactly the same. Which one is quicker or better? Is there a style guide which recommends one?


Solution

  • Both are equivalent. Take a look at the following:

    int[] array;
    
    // is equivalent to
    
    int array[];
    
    int var, array[];
    
    // is equivalent to
    
    int var;
    int[] array;
    
    int[] array1, array2[];
    
    // is equivalent to
    
    int[] array1;
    int[][] array2;
    
    public static int[] getArray()
    {
        // ..
    }
    
    // is equivalent to
    
    public static int getArray()[]
    {
        // ..
    }