StringBuffer Constructors
StringBuffer objects can be created using following StringBuffer
constructors.
1) StringBuffer()
Creates empty StringBuffer object having initial capacity of 16.
Example:
StringBuffer stringBuffer = new StringBuffer();
Here, capacity of stringBuffer object would be 16.
2) StringBuffer(int capacity)
Creates empty StringBuffer object having initial capacity specified.
Example:
StringBuffer stringBuffer = new StringBuffer(50);
Here, capacity of stringBuffer object would be 50.
This constructor can throw NegativeArraySizeException if the passed
argument is less than 0.
3) StringBuffer(String content)
Creates new StringBuffer object having contents same as the argument
string object. The initial capacity of the newly created StringBuffer
object will be the length of the argument string object + 16.
Example:
String str = “Hello”;
StringBuffer stringBuffer = new StringBuffer(str);
Here, capacity of stringBuffer object would be 5 + 16 = 21.
|