Java programming ideas fourth edition Chapter 13 string summary

1. Use of string and StringBuilder

Through the introduction in the book, we know the following conclusions:

Summary: when the string operation is relatively simple (without a for loop, etc.), you can rely on the compiler for optimization. However, if the string needs to use a for loop, you'd better create a StringBuilder object and use it to construct the final result.

Note: when using StringBuilder, avoid writing: append (a + ":" + C), so the compiler still needs to process the internal string first. This string processing is also handled by creating a StringBuilder.

2. Unconscious recursion

Unconscious recursion here refers to In the toString method, you want to display the memory address of the object You cannot use this, but use super toString(). Using this will cause a wireless loop Why does using this lead to infinite loops? Just look at the comments in the following code

The correct way is to remove the comment line Use super toString()

3. Format output

Formatted output uses system out. Printf () or system out. format();

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>