aspose file tools*
The moose likes Java in General and the fly likes Dimensional Travel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Dimensional Travel" Watch "Dimensional Travel" New topic
Author

Dimensional Travel

Dan Temple
Ranch Hand

Joined: Jul 10, 2001
Posts: 93
Okay ... either my eyes are going to explode, or I am on the brink of understanding Lovecraftian geometry. Could someone please tell me if my understanding of multi-dimensional arrays is correct? I understand 2d arrays, but anything beyond that and my brain turns to mush:
A 2d array refers to an array containing one or more arrays. Does that mean a 3d array refers to an array containing one or more arrays which in turn can contain one or more arrays? 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?
Consequently (assuming this is not heat-stroke inspired drivel), in order to refer to that e would I write: arr[3][1][0]? My reasoning being that in order to get to e go to the third index of the main array, the second index of a list listing all the arrays within arrays, and lastly the first index of a list listing all the arrays within the arrays within the arrays??? In other words
{1,{a,b},3,{c,d,{e}},4} = 3rd index
{a,b}, {c,d,{e}}= 1st index
{e} = 0th index?
Okay - my grasp on reality is starting to fade now. If anyone understands this babbling, please let me know
Dan
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
> 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).]


"I'm not back." - Bill Harding, Twister
Dan Temple
Ranch Hand

Joined: Jul 10, 2001
Posts: 93
Thanks Jim!
If multi-dimensioned arrays are that obscure, I'm not going to worry about them (i.e. study for the Programmer Certification). But I will definitely keep in mind the definition you gave for 2d and 3d arrays (a 2d array is an array of arrays .... an nd array is an array of (n-1) arrays).
Thanks for the help!
Dan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dimensional Travel