Package com.day8.StringBuffer;
public class Dome1stringbuffer {
/**
* I. Construction method of StringBuffer:
* 1.public StringBuffer (): Non-parametric construction method
* 2.public stringbuffer (int capacity): Specifies the capacity of the string buffer object
* 3.public StringBuffer (String str): String buffer object specifying string contents
* Two. Method of StringBuffer
* 1.public int capacity (): Return current capacity, theoretical value
* 2.public int long (): Returns the length (number of characters), the actual value
*/
public static void Main (string[] args) {
StringBuffer sb=new StringBuffer ();
System.out.println (Sb.length ());//The number of characters in the container, output 0
System.out.println (Sb.capacity ());//output 16, theoretical value initial container length is 16
StringBuffer sb2=new StringBuffer (10);
System.out.println (Sb2.length ());//actual length is still 0
System.out.println (Sb2.capacity ());//output 10 because the specified length is 10
StringBuffer sb3=new stringbuffer ("kobebryant");
System.out.println (Sb3.length ());//10
System.out.println (Sb3.capacity ());//26=16+10
}
}
Java-stringbuffer Construction Method