Java Learning StringBuffer < good programmers training camp >

Source: Internet
Author: User

<a href= "http://www.goodprogrammer.org/" target= "blank" >android training </a>------My Java notes and look forward to communicating with you!

1.StringBuffer is a string buffer, which is a container.

Features: 1) The length is changeable. 2) Multiple data types can be manipulated in bytes. 3) will eventually become a string by the ToString method.

Method of 2.StringBuffer:

1) storage.

StringBuffer append (): Adds the specified data as a parameter to the end of the existing data.

StringBuffer Insert (Index, data): You can insert data into the specified index position.

2) Delete.

StringBuffer Delete (start,end): Deletes the data in the buffer, contains start, and does not contain end.

StringBuffer Deletecharat (Index): Deletes the character at the specified position.

3) get.

char charAt (int index)

int indexOf (String str)

int lastIndexOf (String str)

int Length ()

String substring (int start, int end)

4) modification.

StringBuffer replace (start,end,string);

void Setcharat (int index, char ch);

5) Invert.

StringBuffer reverse ();

6) stores the specified data in the buffer in the specified character array.

void GetChars (int srcbegin, int srcend, char[] DST, int dstbegin)

3. New Type StringBuilder

1) StringBuilder appeared after the JDK1.5 version.

2) StringBuffer is thread synchronization. StringBuilder is a thread that is out of sync.

3) After development, it is recommended to use StringBuilder

Upgrade three factors: 1, improve efficiency. 2, simplify writing. 3, improve security.

Java Learning StringBuffer < good programmer training camp;

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.