Java-stringbuffer Construction Method

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.