class lab1{
public static void main(String[] args){
int arr[]= new int[2147483647];
System.out.println(arr.length);
}
}
Asked
Active
Viewed 127 times
-2

Kara
- 6,115
- 16
- 50
- 57
-
1Whenever you post code that produces an error, post that error. – Sotirios Delimanolis Mar 04 '14 at 17:44
1 Answers
1
The problem is, as the error states, that the array is too big:
Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit
at lab1.main(lab1.java:7)
This is because there is a set maximum size of arrays in Java.
For more information, you should see: Do Java arrays have a maximum size?