Java String type

Source: Internet
Author: User

1.1. For the String type, when we declare a String type variable, String test = "STRING"; at this time, test is only a reference, and the true String is the STRING.

1.2 · String is an unchangeable class, so when we test + = "BUFFER", the original STRING still exists in the memory. After adding the BUFFER, memory opened up a space, put the STRINGBUFFER string, and point test to this space.

1.3 · StringBuffer class, which can be modified. Not every different string must generate a new object.

1.4. For String constants, if the content is the same, Java considers them to represent the same String object. Using the new keyword to call the constructor always creates a new object, regardless of whether the content is the same or not.

1.5 · immutable class because its object is read-only, there will be no problem with multi-thread concurrent access. However, each State must be represented by an object, which may cause performance problems.

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.