So I have this method here. This is creating a 2D array.
public static int[][] createCacheArray(int cacheSize, int blockSize, int[] memory, int i) {
//Create multi-dimension array for cache.
int [][] cache = new int [cacheSize/blockSize][blockSize];
for (int column = 0; column < blockSize; column++) {
for (int row = 0; row < cache.length; row++) {
cache[row][column] = memory[i];
i++;
}
}
return cache;
}
I would like to store the created Cache 2D array into a 1D array because I will be making multiple 2D cache arrays using this same method and I would like to organize them.
Basically I want to go to array [number] where a Cache 2D array is located and then read the contents of that cache 2D array. If there is another method I would gladly appreciate it.
The other way of doing it is this:
cache = createCacheArray(cacheSize, blockSize, memory, (cacheSize * 0));
cache1 = createCacheArray(cacheSize, blockSize, memory, (cacheSize * 1));
cache2 = createCacheArray(cacheSize, blockSize, memory, (cacheSize * 2));
cache3 = createCacheArray(cacheSize, blockSize, memory, (cacheSize * 3));
Here, cache is 2D array, cache1 is a 2D array, cache 2 is a 2D array and so on, but this is inconvenient. The reason why im asking is because these are fixed 64x16 2D arrays. If an array gets filled, then I have to make another 2D array with the same size. Instead of making multiple variables, I was thinking it was possible to somehow store these onto an array. Like the 2D arrays are books and the 1D array is the shelf.
==================
The 2D arrays have numbers inside them.
After doing AndersonVieira's suggestion, all of my 2D arrays are stored into the ArrayList. This is perfect.
All I want to do now is search for a specific number in all of those 2D arrays inside the ArrayList. But I don't know what code to write to do this. I'm still a beginner in Java.
Map?