All together and Snailren learn java-(13) string

Source: Internet
Author: User
Tags string methods

"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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.