Difference between StringBuffer and StringBuilder, stringbuilder

Source: Internet
Author: User

Difference between StringBuffer and StringBuilder, stringbuilder

1. Comparison of execution speed: StringBuilder> StringBuffer
2. StringBuffer and StringBuilder. They are string variables and changeable objects. Whenever we use them to operate on strings,
It actually operates on an object. Unlike creating some objects like a String, it is faster.
3. StringBuilder: thread-safe
StringBuffer: thread-safe
When we use it in string buffering by multiple threads, the JVM cannot ensure that the StringBuilder operation is safe. Although its speed is the fastest, it can ensure that StringBuffer can be operated correctly. Of course, in most cases, we perform operations in a single thread. In most cases, we recommend using StringBuilder instead of StringBuffer, which is the reason for speed.

Summary: 1. If you want to operate a small amount of data, use = String
2. A single thread operates on a large amount of data in the string buffer = StringBuilder
3. multi-threaded operations on a large amount of data in the string buffer = 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.