If you are just calling the default creation of StringBuffer, the following code will get called(default size of 16 characters).
StringBuffer() {
super(16);
}
abstract class AbstractStringBuilder implements Appendable, CharSequence {
void expandCapacity(int minimumCapacity) { int newCapacity = (value.length + 1) * 2; if (newCapacity < 0) { newCapacity = Integer.MAX_VALUE; } else if (minimumCapacity > newCapacity) { newCapacity = minimumCapacity; } value = Arrays.copyOf(value, newCapacity); }
This expandCapacity() has been called from append() method of StringBuffer. Most of the methods of StringBuffer are synchronized as expected.
For more understanding, you can see the openJDK source code.
No comments:
Post a Comment