Instead of using string constructors, strings can be used directly.
Two special cases:
1) to convert char [] to a string,
(2) using a substring () method of a large string object;
String.Equals () is faster than string.equalsignorecase ();
Try to use StringBuilder to construct a string instead of the "+" operator and String.Concat () (unless it is an expression, String s = a + B + c);
StringBuilder is not synchronized (not synchronized), so it is faster than stringbuffer;
In string[buffer| Builder] constructor, because creating a buffer that is too small can degrade performance;
String.Length () ==0 is faster than String.Equals (""). Use Java 6 o'clock, string.isempty () faster;
Calling String.tostring () is meaningless;
Because a string is immutable, all of the string's methods return a new instance by returning the modified string.
The String.Split (regex) actually simply invokes the Pattern.compile (Regex). Split (this, limit), and each compile () returns a new pattern. So if you call split frequently, it's best to create a single pattern instance and reuse it instead of split ().
The above is to share the content of this article, I hope you can enjoy.
Please take a moment to share the article with your friends or leave a comment. We will sincerely thank you for your support!