This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
You can declare the array size: Object This is meaningful if you make an empty array. But since you are providing values in the declaration it will take the size from the values. I'm pretty sure. Try this for fun and illumination:
This says the array holds two items but I only provided one value. See if it held the second position with a null or if you get an index out of bounds exception. And let me know.
If you know the answer ... don't tell!
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
OK, now I think I know what the issue is: you want, somehow, the Java array variable's type to include the size of the array -- is that it? In Java, array variables don't include any notion of dimensions. Even if you allocate an array at some fixed size -- i.e.,
int array = new int;
there's nothing about the variable "array" that includes the notion of 64-ness or 8-ness, and you can later say
array = new int;
Joined: Apr 22, 2005
OK, and now how do I store all my values on the array, I have this, and the program output an error. Here is what I have.