Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
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.
<< StringBuffer StringBuffer and Java String >>

Post new comment