int arr[] = new int[6];
int[] arr = new int[6];
What is difference between them?
If there is no difference then what is the purpose of having two different ways?
The difference is if you have multiple declarations. Otherwise it is a matter of taste
int[] a, b[]; // a is int[], b is int[][]
int a[], b[]; // a is int[], b is int[]
The int[]
is preferred in Java. The older int a[]
is to make C programmers happy. ;)
Confusingly you can write the following, due to obscure backward bug compatibility reasons. Don't do it.
public int method()[] {
return new int[6];
}
It's just some "sugar" that Java gives the programmers. It works exactly the same way and is equally efficient. It just makes it easier to learn the syntaxes.