int[][] arr = new int[10000][10000];
for (int x = 0; x < 10000; x++) {
for (int y = 0; y < 10000; y++) {
arr[x][y] = 5;
}
}
Obviously, I get an OutOfMemoryError, so what would be the best data structure to use to hold that amount of data (It would have to be similar to a 2d array [row x column]). I would also need to search through it and change elements. So what data structure would be the best for this scenario?
EDIT: To Clarify: -All the elements in the array HAVE to be ints. -All the elements in the array will be different values. -i dont have to use a two dimensional array...I was wondering if there is any BETTER data structure to use to store 100 million integers, rather than a two dimensional array, so that it WOULDN'T give me a OutOfMemoryError, because there has to be a better data structure out there with a good space complexity??