Re: Arrays in java
On 7/9/2012 10:54 AM, mmc.java wrote:
> I am just starting to learn java and wanted to know when creating an
> array if there is any reason why you choose one of the following over
> the others or if it is just a styling choice by the developer
>
> int productIDs[] = {10,20,30};
This one, I suspect, is a holdover from C/C++, where the array specifier
has to come after the variable name. I'd recommend not using it, since
it makes it less clear that 'int[]' is the type.
> int []productIDs = {10,20,30};
> int[] productIDs = {10,20,30};
These two are effectively equivalent, differing only in whether you
think "int []" or "int[]" is a more natural way to specify the type. I
tend towards the latter, since "[]" is bound to the int type and not to
the name of productIDs.
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
|