"I haven't written this series for a long time. In fact, there are also in the look, but feel some very basic are written up boring. Now the plan is to read the whole book, and finally integrated into a blog, to filter out some of the usual unnoticed or more in-depth understanding "
In the writing program, string strings are very much manipulated. The use of strings in peacetime only uses a subset of features. This time we'll look at what the main things are about strings. This is mainly explained in the following aspects: string itself, string format output, regular expression, scan input class scanner class.
A, String
When we define a string object, such as String test = "Snailren is so handsome". As we've said before, the contents of the string are saved in the static store, and the test object is in the heap. Therefore, we are unable to modify the contents of the string. The other string methods are the newly created string.
In Java, there is no overloaded operator (good fun) in C + +. Only "+" and "+ =" are overloaded. These two overloads are very well understood and can be used for string types of connections. At the time of the connection string, the Java compiler creates a new StringBuilder class when implemented, invoking the "+" effect of the object's Append method.
For the selection of string, StringBuffer, Stringbilder, you can refer to the following: "References:
When we are using a string buffer to be used by multiple threads, the JVM does not guarantee that the StringBuilder operation is safe, although he is the fastest, but can ensure that the StringBuffer can be operated correctly. Of course, most of the time we are in a single-threaded operation, so in most cases it is recommended to use StringBuilder instead of StringBuffer, which is the reason for speed.
Summary of the use of the three: 1. If you want to manipulate a small amount of data with = String
2. Manipulating large amounts of data under a single-threaded operation string buffer = StringBuilder
3. Multi-threaded operation string buffer operation large amount of data = StringBuffer "
On the
All together and Snailren learn java-(13) string