While running my java code i got an error like this.please help me to over this error...i want to know the maximum size of an STRING ARRAY...
-
3See this link stackoverflow.com/questions/15460779/…Deepu--Java– Deepu--Java2014-03-12 06:42:44 +00:00Commented Mar 12, 2014 at 6:42
-
Limit of the Integer numberKick– Kick2014-03-12 06:43:28 +00:00Commented Mar 12, 2014 at 6:43
-
This looks useful.Josh M– Josh M2014-03-12 06:44:28 +00:00Commented Mar 12, 2014 at 6:44
-
1It's hard to tell what the problem is here - are you actually running out of memory in your real application? If so, have you tried changing the maximum heap size? Or did you only get this error while trying to create deliberately-huge string arrays?Jon Skeet– Jon Skeet2014-03-12 06:47:09 +00:00Commented Mar 12, 2014 at 6:47
2 Answers
The maximum length for any array at the moment is Integer.MAX_VALUE which is approximately 2G for both 64 and 32 bit VM.
The reason for this that the new operator accepts int as length parameter (for instance new int[intLength]). There are proposals to allow long in a future release of Java.
If your array/String's length is less than Integer.MAX_VALUE, try to increase your max heap size - for instance:
-Xmx4g where 4g means 4GB
Comments
the Array size is limited only with the heap size. to increase the heap allocation for your program use the
-Xmx1500m
as a jvm argument when running you application.
java -Xmx2000m .......
You can go up to 4GB for 32 bit JAVA and more on 64bit.
3 Comments
new