| Java Arrays, Objects, Methods | CS 161 - Java |
"Declaring a variable of array type does not create an array object or allocate any space for array components. It creates only the variable itself, which can contain a reference to an array."
from: Java Language Specification, Gosling, Joy, and Steel, 1996
new
, just
like other objects.
Question: Any idea why?
Tip: If you need a colllection's size to change consider using java.util.Vector or another collection class instead of arraysint[] intArray = new int[4]; // elements initially set to 0 CreditCard cards[] = new CreditCard[MAXCARDS]; // elements initially set to null // notice the [] can be placed with the field name // or the type; though the latter is "better"
|
jwd |