posted 25 years ago
Errr... not quite. When an array is created, any elements not initialized will be set to the appropriate default value for the type of the array. If it's an array of primitive numerics (byte, char, short, int, long, float, double) then the default value is 0. If it's boolean, the default value is false, and if it's any kind of reference type (any sort of Object, including String) then the default value is null.
As for Java2Learner's statement about "when you declare a variable, you have to initialize it, unless it's static" - that's incorrect. If it's a local variable then you have to initialize it (and local variables can't be static anyway). If it's an instance or class variable (i.e. a member variable with or without "static" modifier) then you don't actually have to initialize it - if you don't, it will get the appropriate default value for its type, as I listed above (0, false, or null).
"I'm not back." - Bill Harding, Twister