I have recently been thinking about the difference between the two ways of defining an array:
int[] array
int array[]
Is there a difference?
They are semantically identical. The int array[]
syntax was only added to help C programmers get used to java.
int[] array
is much preferable, and less confusing.
There is one slight difference, if you happen to declare more than one variable in the same declaration:
int[] a, b; // Both a and b are arrays of type int
int c[], d; // WARNING: c is an array, but d is just a regular int
Note that this is bad coding style, although the compiler will almost certainly catch your error the moment you try to use d
.
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