You don't need to use the String constructor, just use strings if possible.
Two special cases:
1) Want to convert char [] into a String,
2) Use a large String object substring() method;
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, so it is faster than StringBuffer;
Add capacity parameters to the String[Buffer|Builder] constructor, because creating a buffer that is too small will degrade performance;
String.length()==0 is faster than String.equals(""). String.isEmpty() is faster when using Java 6;
It makes no sense to call String.toString();
Since String is immutable, in the String method, all the modified String returns a new instance;
String.split(regex) In fact, a simple call to Pattern.compile(regex).split(this, limit) is called, and each time compile() returns a new pattern. So if split is called frequently, it is best to create a single Pattern instance and reuse it instead of split().
The above is what this article is going to share with you, I hope you like it.
Please take some time to share the article with your friends or leave a comment. We will sincerely thank you for your support!