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.