Trying to get maximum array length. I found on net that maximum array length is actually maximum integer value.
I used in my code this piece of code:
int[] array = new int[Integer.MAX_VALUE]; // 2^31-1 = 2147483647
And i get this kind of error :
Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit
at IntMaxValueArrayLength.main(IntMaxValueArrayLength.java:7)
I also found on internet that 2^31-1 can't be maximum value, that i need to subtract some numbers, i tried to subtract like 100000 but still get the same error.