I was trying to create a int[] type array in Java with a user input based length. Below is the code for the same :
int[] change = new int[max+1];
When the value of max = 2147483647, the compiler shows the below error code : type here
java.lang.NegativeArraySizeException: -2147483648
I know that the upper limit for int in Java is -2147483648 to 2147483647 (-231 to 231-1), but why is the size of array going negative with a addition (is it looping back to the lower limit?). The problem remains the same with long[] type array. So, does Java not support array size above 231-1 ?