Fast Color Network Cai ticket PHP source thinkphp Framework Development Webpack and Vue

Source: Internet
Author: User
Tags php source code ticket

String, StringBuffer, and StringBuilder are common strings in Java, and they are all familiar to the difference, but how does the bottom end work? Today, we will analyze the differences between these three types of string operations, their respective principles and usage scenarios.??????? Please respect the author's labor results, reproduced please indicate the original link: fast color network CAI ticket PHP source code https://dashengba.com Holy Source Forum Buckle 32,663,975,971, String??????? Let's take a look at some of the source code in the JDK string: View Code???????? You can see that the string class and the value are final types, which means that the string cannot be inherited and value cannot be overwritten. When a new string object is initialized through the constructor of string, it is only assigned based on the value and hashcode of the incoming reference object. Look at the following example: Vew Code??????? After performing the Javac Stringtest.java, look at the generated class file by Javap-v stringtest.class: View Code???????? You can see that references to the same string "ABC" are the same (for the same position in the constant pool), which saves memory space, but the drawback is that the frequent concatenation of strings creates a waste of memory space. (Note that the concatenation of this string operation, starting from JDK8, will be automatically compiled into StringBuilder, is not very 666 ^_^, but it is recommended not to go through the JDK path to automatic.) See the following code: View Code??????? Then look at the class file through Javap: View Code II, StringBuilder??????? Also first to see StringBuilder Source: View Code???????? You can see that the value of StringBuilder is a char array (of course, from JDK9, value changes from a char array to a byte array). Each append is implemented by invoking the system.arraycopy of native (called in GetChars). Third, StringBuffer S??????? The source code for Tringbuffer is as follows: View code???????? As with StringBuilder, the use of a char array to save Value,append is also called AbstractstriThe Append method of Ngbuilder. The difference is only that the char array has the transient keyword, and the method adds the synchronized method.??????? In summary, the usage scenarios for String, StringBuilder, and StringBuffer are as follows:??????? String is recommended when working with fixed-length strings;??????? StringBuilder is recommended when processing variable-length strings, and is a single-threaded environment;??????? StringBuffer is recommended when working with variable-length strings and in a multithreaded environment.

Fast Color Network Cai ticket PHP source thinkphp Framework Development Webpack and Vue

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.