4D array of references to strings
Posted on 1998-04-01
I'm fairly new to Java and I need a little help with a very specific problem...
I need to create a 4D array datatype with the last dimension holding strings. In Turbo pascal it might look like
joe : array[1..7,1..6,1..60,1..168] of String;
In fact, these are the exact dimensions I need but that doesn't really matter. Now, knowing that this question is too easy for all you guys, I have something else that I need help with.
Instead of just holding strings, I'd like this structure to hold references to strings in order to save memory. The reason is this... Throughout this whole array, there might only be as few as 100 distinct strings but they all get copied a couple hundred times so that they each fill 100 array elements at a time. Instead of duplicating the strings in memory every time I copy them into a new array element, I'd like to just store references to those strings. That way, each element of the array will take 4 bytes (or whatever a Java reference takes) instead of 30 odd bytes for the string, hence saving mondo memory.
So, here's what I need...
I need a class with a constructor that when instantiated, will create this 4D array of whatever data type is necessary to store references to strings. I'd like to be able to specify the dimensions by passing parameters, if that's ok... So, this class would be instantiated like this, I think...
4dArray joe = new 4dArray(5,6,30,168); //how do I access the individual elements?
I'll also need a few basic instructions on how references work in Java since I haven't been able to find any information on them... Even in the Sunsoft Tutorial (am I blind?). If somebody knows of another good URL where one can get good info on Java, I'd be very much appreciative. I'm familiar with references in PERL ( \variable-name ) and pointers in Pascal but I don't know if that's how Java works at all. Once I have that information, I think I'll be able to write my methods, etc. Oh, if you need a length for the strings, set them at 30.