Board index » jbuilder » Arrays??

Arrays??


2005-05-23 03:27:12 AM
jbuilder1
Hi.
Somebody can tell me which difference is there between
double q[] = new double[15] and
double[] q = new double[15]
and if there is differences how can I initialize with values???
Thanks
 
 

Re:Arrays??

There is no difference, it is a matter of choice/readability. According to
Sun's tutorial and common consensus the latter format is the preferred one.
Also, arrays of doubles are already initialised to a default value of 0.0.
If you want to initialise to other values you could use the alternative
syntax
double q [] = {1.0, 5.1, 7.6, 8.2, 3.1};
or of course the preferred
double [] q = {1.0, 5.1, 7.6, 8.2, 3.1};
If you use this syntax, the array is sized to the number of elements between
the parentheses.
You can also create an anonymous array which is usually passed as a
parameter into a method
myMethod(new double[] {1.0, 5.1, 7.6, 8.2, 3.1});
See Sun's tutorial :-
java.sun.com/docs/books/tutorial/java/data/arrays.html
Arth
"Davisote" < XXXX@XXXXX.COM >wrote in message
Quote
Hi.
Somebody can tell me which difference is there between
double q[] = new double[15] and
double[] q = new double[15]
and if there is differences how can I initialize with values???

Thanks