Hey,
I'm just learning Java, but from my background in C/C++ I have a question.
Won't this example potentially produce unexpected results later on in the program?
Code:
StringBuffer s3 = new StringBuffer(2);
s3.insert(0, "Hello");
System.out.println(s3);
Since the buffer was initially set to 2 characters and what is being inserted into it is 5 characters, is it possible that the memory holding those extra 3 characters will be overwritten? Or does Java just change the size of the buffer to hold the 5 characters?
In C a string is terminated with a \o if I remember correctly. So "Hello" actually would take 6 characters, not 5. Is this true of Java also?
Thanks,
Jason