> Okay ... either my eyes are going to explode, or I am on the
> brink of understanding Lovecraftian geometry.
Well, either one sounds cool for us spectators. Provided we're far enough away. Do you think you could rig a live video feed?
> A 2d array refers to an array containing one or more arrays.
First,
you should know that 2d arrays, 3d arrays, and higher dimensions aren't strictly defined in
Java - only 1d arrays are directly supported. There are more-or-less standard mechanisms to support higher dimensions, but they may require extra code to implement, and there can be more than one way to define some of these term. I will try to give what I understand to be the "standard" interpretation. With that in mind...
A 2d array refers to an array whose elements are
all 1d arrays. Preferably, all arrays of the same length, to minimize confusion. I suppose you could also allow nulls, which would be defined as equivalent to an array of zeros, but this is already going to require extra code to support this possibility, and is probably only useful as an optimization for sparse arrays. Similarly you can allow the arrays to have different sizes if you assume that all index-out-of-range values are zero. Anyway...
> Does that mean a 3d array refers to an array containing one
> or more arrays which in turn can contain one or more arrays?
Replace "one or more" with "nothing but" and you are correct. A 3d array is an array of 2d arrays. Again, preferably all of the same size.
> For example, is this a 3d array:
>
> arr={1,{a,b},3,{c,d,{e}},4}? i.e. 3d because there is an
> element e which is 3 arrays in?
Nope. The problem is that there are different types of arrays mixed together indiscriminately - arr is an array containing an int, a 1d array, another int, a mixed-dimensional array... It isn't pretty.
I don't know any standard term for what you've made - I improvised "mixed-dimensional array", which has probably been used by others before me; I just haven't heard it.
> Consequently (assuming this is not heat-stroke inspired drivel),
OK, we'll pretend that's not the case, for now.
> in order to refer to that e would I write: arr[3][1][0]?
Ummm... arr[3][2][0] I think. And since it was mixed-dimensional in the first place, you could only have declared arr as Object[]. Which means you'd need to insert several casts:
(int) (((Object[]) ((Object[]) arr[3])[2])[0])
I'm assuming e was an int here...
Here's the breakdown...
<pre>
{
1, // arr[0]
{ // arr[1] begin
a, // arr[1][0]
b // arr[1][1]
}, // arr[1] end
3, // arr[2]
{ // arr[3] begin
c, // arr[3][0]
d, // arr[3][1]
{ // arr[3][2] begin
e // arr[3][2][0]
} // arr[3][2] end
}, // arr[3] end
4 // arr[4]
}
</pre>
Hope that helps...
[This message has been edited by Jim Yingst (edited August 02, 2001).]