Java-preliminary Understanding-Common Object API (string class-Common functionality-intern method)

Source: Internet
Author: User

One.

For a parse of the string memory.

Now introduce a method, for a while to use, but the actual development is not uncommon.

Intern () can operate on a constant pool,

S1 is an object, and then uses the S1 object to invoke the method in the operation constant pool, calling this method to return the object in the pool.

And then the comparison, S1==s2? The result is false, and it is one thing to follow the same notation.

Here the S1 is an object in the heap, I object to the pool to find, not in the pool, and then in the pool built a return to the.

You can get it back in the pool without creating a return.

(Eclipse look at the source, put the cursor on the string, click F3 to switch directly to string.class this source file.) Holding down CTRL, using the mouse against the string, there are two options, one is explanation, the other is implementation. Click to explain)

For string S1=new string ("abc"); Here new is two objects, and the "ABC" string object is maintained in the object in heap memory. The S1.intern is to get the data in the pool. The data in the pool is the shared data.

Java-preliminary Understanding-Common Object API (string class-Common functionality-intern method)

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.