Java------stringbuffer

Source: Internet
Author: User

Stirngbuffer

The contents of the string can be deleted

The composition of a string is implemented by this class.

StringBuffer is a container many methods are the same as String

StringBuffer are variable-length

Characteristics:

Variable length

You can add multiple types

Will eventually become a string through the Tostirng method

StringBuffer function: Add, delete, change, check, of course, there are storage functions.

1. Storage

Append () adds the specified data as a parameter to the end of the existing data.

Insert (index, data) can insert data into the specified index position.

2. Delete

StringBuffer delet (start,end): Deletes the data in the buffer, containing start does not contain end.

StringBuffer Deletcharat (index): Delete the character at the specified position

3. Get

Char charAt (Index):

int indexOf (String str):

int lastIndexOf (String str):

int Length ():

String substring (int start,int end)

4. Modifications

StringBuffer replace (int start,int end,string str)

StringBuilder appeared after the JDK1.5 version.

StringBuffer is thread-synchronized

StringBuilder is thread not synchronizing

StringBuilder A variable sequence of characters. This class is used as a simple replacement for stringbuffer.

In most implementations, it is faster than StringBuffer.

It is not safe to use an instance of StringBuilder for multiple threads, and StringBuffer is recommended if such synchronization is required.

Java------stringbuffer

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.