several ways to concatenate Java strings Several ways of string representation StringBuffer and StringBuilder and string inheritance relations
Connection of Strings
Connection method for 1.String
You can see that the connection is made by creating a new two-length character array and then connecting.
Storing strings in 2.StringBuilder its practical is a char array, capacity is actually specifying the size of this char array, The StringBuilder connection method is inherited by the Abstractstringbuilder method, and the thread is unsafe.
When the append (str) function is called, it is first judged that the string array of values used to store the string has not enough size to store the string that will be added to the StringBuilder. If not enough, then call expandcapacity (int minimumcapacity) to double the capacity (typically twice times the expansion)
3.StringBuffer connection method, using the synchronization (synchronized keyword), thread-safe, but this will be relatively slow down.
4. "+" number stitching
When using + splicing, the + sign will be transformed into StringBuilder append mode, that is, each use + will establish a StringBuilder. Therefore, inside the loop means that every time a loop is executed, a StringBuilder object is created. So do not use the + sign inside the loop to build a StringBuilder or Stirngbuffer outside the loop.
Several ways to concatenate Java strings