That would be 2GB, so you'd have to run the JVM with more than that amount of memory, or you'd get an OutOfMemoryError before reaching that limit.
The source code of the java.lang.String class -to be found in a file called src.zip somewhere in your JDK installation- should tell you for sure.
Why is it really so interesting to know what the limit is to the amount of data that you can store in a String? If you are writing a program which migh approach this limit, then you are probably making a mistake in the design.
It doesn't say in the String code, but you can see that there is a char[] hidden in the String class. Now the index of an array is an int, so the largest you can declare is 2147483647, which is equal to 0x7fffffff or 2 to the 31st - 1, as you have already been told.
If you look in the Java Language Specification, you can see exactly what it says about maximum sizes of arrays. It tells you . . . nothing.
I agree with Jesper de Jong . String are not meant to be hold such a large data. String are mainly designed to hold temporary data. you should relook into your design.
Post by:autobot
Yeah, but is it art? What do you think tiny ad?
a bit of art, as a gift, that will fit in a stocking