Why would the StringBuffer have a limit on its size?
I went through some of the links : http://www.coderanch.com/t/540346/java/java/maximum-size-hold-S
Answer is different based on System architecture.
This old machine when I posted answer on 2012
Max Length of characters = 37748734
Java Version : 1.6.0_35
OS : Windows 7
System Architecture : 32bits (x86)
RAM : 2 GB
Processor : Pentium Dual Core E5800 3.20GHz
On 2016
Max Length of characters = 301989886
Java Version : 1.8
OS : Ubuntu 14 LTE and Windows 7
System Architecture : 64bits (x86_64)
RAM : 8 GB
Processor : Intel(R) Core(TM) i3-4130 CPU @ 3.40GHz
Run This program your self
StringBuffer strbTest = new StringBuffer();
long len = 0;
try {
System.out.println("Wait.... til number not generated.");
while(true) {
strbTest.append("a");
len++;
}
} catch (OutOfMemoryError e) {
System.out.println("Max length on your system is "+len);
System.out.println("Error");
}
System.out.println("End");
Output
Max length on your system is 37748734