The 1.String object is immutable, and every method in the string class that appears to modify a string value is actually creating a new string object that contains the modified content, so after modifying the string, you want to print a new value, either directly or by using a variable to accept , Direct printing of the original string reference does not change.
2. Connecting string strings via "+" is actually a compiler that automatically introduces the StringBuilder class, implemented through the Append () method.
3. When writing the ToString () method for a class, if the string operation is relatively straightforward, you can use "+" directly, relying on the compiler. However, if a loop is used in a method, it is best to create a StringBuilder object yourself and use it to manually construct the final result. If you use "+", the compiler will constantly create StringBuilder objects during the loop, affecting efficiency and causing excessive garbage. Although Java has an automatic recovery mechanism, but it is never real-time, but only when the memory is not enough to recover, so as far as possible to produce less garbage is also necessary.
4. In the ToString () method, do not use this directly, such as the use of a = "B" + this + "C" statement, the compiler does not recognize this when it will call the ToString () method, this time will fall into the recursion, and constantly error.
The 5.Formatter () class enables finer-grained control of string-string output formats, which can be referenced when needed.
6.string.format () method, the implementation principle is also the internal creation of formatter objects, the implementation of formatting.
7. Proficiency in regular expression writing specifications, while familiar with the use of the pattern and Matcher class API, the combination of the two functions is very powerful, almost can satisfy the operation of the string.
Java Programming Ideas: strings