This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
It allows you to declare it later. And each of those 10 doesnt have to be the same parameters.
E.g.
[0] has [3][5] [1] has [34][2] [2] has [8][7] . . [9] has [2][63]
E.g.
int[][][] i = new int[10][][]; i[0] = new int [3][5] i[1] = new int [34][2] i[2] = new int [8][7] . . i[9] = new int [2][63] [ September 01, 2007: Message edited by: Jesus Angeles ]
Originally posted by Steve Harmison: ...int[][][] i = new int[10][][];
Surely Java does not know how much space to set aside for the array, as we have left the rightmost arguments blank!
Actually, it does know how much space to set aside for "the array."
In Java, multi-dimensional arrays are just arrays of arrays. And the elements of the array are just references -- not the objects themselves. So in this example, "i" simply references a single-dimension array of length 10, where each element is a reference to another array. (At this point, these 10 references are all null because we haven't put anything in "i" yet, but a null reference takes the same space as an object reference.)
In other words, the "size" or length of a multi-dimensional array is simply the first dimension, because it's really no different than a single-dimension array. Additional dimensions specify separate objects (arrays) that are in the first array. [ September 01, 2007: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
I just read in my study guide in the past few days that [] is the same as an object as far as Java is concerned.
Whenever you see something like this, you have to allow for the fact that (like marc weber states) the first [] = new [10] only allocates the first array reference, the remaining two [][] being just places to put information about an arrary once it is created.
I never gave it a great deal of thought, but what Jesus Angeles will be of use in thinking about what is going on.
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Originally posted by Nicholas Jordan: ...the remaining two [][] being just places to put information about an arrary once it is created...
The empty brackets are necessary because they provide information about the type -- both when declaring the variable and when creating the object. Remember that the type of references an array holds is also part of the array's type. For example, String[] is an array that holds references to Strings. But String[][] is an array that holds references to arrays (that in turn hold references to Strings).
Steve Harmison
Greenhorn
Joined: Sep 01, 2007
Posts: 4
posted
0
Thanks everyone.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.