Thinking in java---the 13th chapter-string

Source: Internet
Author: User

Write in front:
There are too many things to do, the blog is not very thin. Will write what they think is fun, important places. I hope you will enjoy your discussion and share your ideas. Let the "spark of thought collide" to achieve.

Strings are involved in almost every operation, so strings are especially important.
13.1 Immutable string
The string class seems to modify the string to be worthwhile, in effect creating a completely new string object that contains the modified string content, while the original string object was not moved at all.

13.2 + with StringBuilder
StringBuilder is much faster, if you are interested, you can write two different ways to measure time with + and StringBuilder. You can also configure the environment variable with javap-c ClassName (class name) to see what the JVM bytecode looks like.

It's good to use StringBuilder when there's a loop.
Other than that!

append(/*一个字符串*/);

Don't use something like this.

append(a":" + c);

This way the compiler will push into the trap and create another StringBuilder object for you to handle the string operations in parentheses.

13.3 unconscious recursion

System.out.println("String"this);

Here, the compiler sees a string followed by A +, after which the object is not a string, and the ToString method of this is called. The This.tostring () method may also have this object, so it will continue to be recursive.

13.4 operation on a string
Google for yourself

13.5 Formatting
is a Formater class, for example

System.out.format("%d"x);

It's like C.

13.6 Regular Expressions
A method for efficiently matching strings. Every day will come to share several

13.7 Scan Input
Process the input and analyze the input data.
It's best to use scanner or regular expressions to analyze the scan.

13.8 Split string
StringTokenizer
Because there are two of the above, it has been forgotten = =

Thinking in java---the 13th chapter-string

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.