Differences between string, stringbuffer, and stringbuilder

Source: Internet
Author: User

String, stringbuffer, stringbuilder
String is an unchangeable volume, that is, it cannot be modified after it is created.
Stringbuffer is a variable character sequence, and the object value can be changed.
The stringbuilder and stringbuffer are basically the same, all of which are variable character sequences. The difference is that stringbuffer is thread-safe and stringbuilder is thread-insecure.

After figuring out the principles of the three, you can use different character sequences in different scenarios:
1. Use Cases of the string class
The string class can be used in scenarios where strings do not change frequently, such as constant declarations and a small amount of variable operations.
2. Use of stringbuffer
When string operations (such as splicing, replacement, and deletion) are performed frequently and run in a multi-threaded environment, you can consider using stringbuffer, such as XML parsing, HTTP Parameter Parsing, and encapsulation.
3. Use Cases of stringbuilder
When string operations (such as splicing, replacement, and deletion) are performed frequently and run in a single-threaded environment, you can use stringbuilder, such as SQL statement assembly and JSON encapsulation.

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.