Mark - I don't think 1000 x 1000 is large enough to warrant the additional complexity and decreased speed of a sparse array. It's a possibility to keep in mind for the future though, if you find you need a finer grid than you have now.
[JuanP]: I think that you need a performance solution and not a algorithmic solution. Sorry, but I don't know what this means here. Some sort of algorithms will be involved whatever the solution is, and performance will
probably become a noticeable factor (though not necessarily a critical one). I don't know if that addresses what you're talking about or not though.
[CLG]: Wouldn't the array of arrays only be 1001 objects to begin with? With the array that holds 1000 other arrays, and the 1000 other arrays totallying 1001? Yes. And each of those 1001 arrays would be big enough for 1000 object references, so ~4000 bytes per array, 4004000 bytes total, approximately 4 Mb. The references take up the same amount of space whether they're null or not - of course if they're not null then they probably refer to other objects, and those objects take up space. I'm assuming that's negligible initally. The various arrays also probably have some minor overhead (additional memory cost) which we're overlooking.
[Bill]: My approach would be to allocate a single 1000000 element array of Object and write methods for index conversion. Yeah, that works too. Total memory is about the same. Ease of allocation? Calling new Object[1000][1000] creates everything you need in one step, pretty easy. I'm not sure I'd see any reason to use wrapping here unless this is a termite video game.
I don't have a strong preference though between new Object[1000][1000] and new Object[1000000] - I suppose I'd want to try both and measure access times to see if there's a difference.
As for ability to mix termite and non-termite objects - well that's a separate issue from whether we use array of arrays or one big array or a sparse array; it's determined by the type of the elements
in the array. My first thought is to create a GridPoint class representing everything at a given point; could include a Termite or a PheremoneCount or both, plus whatever other elements are useful. Or maybe all the info we need can be encoded into an int or something smaller instead. E.g. perhaps all we need is the termite ID number (7 bits, could be 0000000 for no termite at all) and a rough pheremone intensity level (9 bits). Everything we need fits in a short, so use a new short[1000][1000] or new short[1000000] for about 2 Mb and no additional object. Well, there probably are more objects somewhere, but we've drastically reduced the number.
Bill - what do you mean by "ease of switching geometry"? What sort of switch?