How can I initialize an array of size 1000 * 1000 * 1000 * 1000
of all Integer.MAXVALUE
?
for example, I want to make this int[][][][]dp = new int [1000][1000][1000][1000];
all have max value as later I need to compare a minimum.
I tried
int [] arr = new int arr[N];
Arrays.fill(arr,Integer.MAXVALUE);
but it doesn't work with multidimensional arrays, can anyone help?
You'll have to do this to fill your multi-dimensional array:
for (int i = 0; i < dp.length; i++) {
for (int j = 0; j < dp[i].length; j++) {
for (int k = 0; k < dp[j].length; k++) {
Arrays.fill(dp[i][j][k], Integer.MAX_VALUE);
}
}
}
You won't however be able to initialize new int[1000][1000][1000][1000]
unless you have at least 3.64 terabytes of memory. Not to mention how long that would take if you did have that much memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With