I've got a rather large portion of 2-Dimensional data that I'm trying to work with, every piece of data has an (x, y)
coordinate, and then an array of data located at that coordinate.
What I'm doing right now is just using a HashMap
to cycle through it, with a method checking for the coordinate to know when to go to the next 'line' (so if the data is [0-10] for x
then it tests for 11 (and multiples) to calculate where to display a new line). This is rather cumbersome, and I'm hoping there's an easier solution, but I haven't been able to find one on Google or SO yet that fits.
What I'm trying to do is something to the following pseudocode :
HashMap thisMap = (key = IntArray[][], value = IntArray[] )
Where I could set a particular 2-d Int array as the key for the entire thing, and then assign the values through a loop (and get the values just as easily) in an iterable way. The closest thing I can think of would be how PHP
handles multi-dimensional arrays and foreach()
where you can nest the foreach()
loops, but I'm not sure how this would work in Java.
The goal is eventually to be able to write two methods, one that will iterate along the X-axis
(first digit), then proceed to the next row; and another that will take it as 'frames' and iterate over the Y-axis
. I'm not wanting anyone to write these for me, or even the HashMap code, but I'm hoping to be pointed in the correct direction on how to do this (if it is possible) with just the standard libraries available in Java SE and not overriding anything. If not, then hopefully directions in how to override safely.
NOTE
Another problem here is the set of data is quite large, and what I initially tried to do was to write my own Tuple class
, but the first time I used it I ran out of heap memory, which is why I'm trying to stick to a single 2-d primitive int array for this.
EDIT
I found these : Java usage of HashMap or Map with multidimensional arrays
Java HashMap associative multi dimensional array can not create or add elements
How to implement a Map with multiple keys?
however they do not seem to be attempting to achieve the same thing.
EDIT 2
another complication is that the keys in the Y-axis
are not sequential, though they are ordered low to high.