Difference between stringbuilder class and string class

Source: Internet
Author: User

The string object cannot be changed. Every time a method in the string class is used, a New String object must be created in the memory, which requires a new space for the new object. If you need to modify the string repeatedly, the system overhead associated with creating a new String object may be very expensive. If you want to modify the string without creating a new object, you can use the stringbuilder class.

I don't want to give an example of the string class. It is widely used. For beginners like me, the stringbuilder class is rarely used. Generally, it is easy to encounter the following situation: when many strings are connected together in a loop, the stringbuilder class can improve the performance. SpecificallyProgramWhen writing SQL statements, for example, if we need to execute multiple SQL statements at the same time, we can use the stringbuilder class to execute multiple SQL statements at the same time, in this way, SQL transactions can be rolled back.

This is just a problem for a beginner. I also hope you can leave a message and talk about the special usage of stringbuilder, which is commonly used in other places, it can reduce freshman like me and avoid detours. Thank you for your support.

Related Article

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.