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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With