Deep Knowledge about java. lang. String

Source: Internet
Author: User

String is a constant, and its object cannot be changed once it is created. When + is used to splice strings, A New String object is generated instead of appending content to the original String object. 1. String Pool (String Pool): String str3 = "bbb" is assigned to the String Pool. Step 1: Check whether the object "bbb" exists in the String Pool. If it does not exist, create a "bbb" object in the String Pool, and return the address of the "bbb" object in the String Pool to the referenced variable str3, in this way, str3 points to the "bbb" String object in the String Pool. Step 2: If the object exists, the object address is directly returned if it is not created. Note: String str4 = "bbb"; then modify str3 = "ccc"; a new one will be created without affecting str4. 2. For String str = new String ("aa"); a) First, find the String object "aa" in the String Pool. If yes, the "aa" object is not created in the String Pool, and an "aa" String object is directly created in the heap, then return the address of the "aa" object in the heap and assign it to the str reference. As a result, str points to the "aa" String object created in the heap. B) If no, create an "aa" object in the String Pool, and then create an "aa" object in the heap, then return the address of the "aa" object in the heap and assign it to the str reference. As a result, str points to the "aa" object created in the heap.

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.