Java: int[] array vs int array[]

xuma202 picture xuma202 · Jan 28, 2013 · Viewed 353.3k times · Source

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?

Answer

Eng.Fouad picture Eng.Fouad · Jan 28, 2013

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()[]
{
    // ..
}