The values of Sring a and String B are the same. Do you want to point to the same address?

Source: Internet
Author: User

A String is a String in java. It contains several characters enclosed in double quotation marks, such as "Abc" and "one day ".
The String class is immutable (final). Any change to the String class will return a new String class object. in this way, the reference of the String class is passed to a method. Any change of the method to the String has no effect on the object pointed to by the original reference. This is similar to the basic data type.
String a = "hello, word! ";
 
String B = "hello, word! ";
 
String c = "hello! ";
Does a and B point to the same address? This issue is very intense in various forums. In fact, it is very simple. Just like the memory address of these strings!
String a = "hello, word! ";
 
00000042 mov eax, dword ptr ds: [02A62208h]
 
00000048 mov dword ptr [ebp-44h], eax
 
String B = "hello, word! ";
 
2017004b mov eax, dword ptr ds: [02A62208h]
 
00000051 mov dword ptr [ebp-48h], eax
 
String c = "hello! ";
 
00000054 mov eax, dword ptr ds: [02A756F8h]
 
2017005a mov dword ptr [ebp-4Ch], eax
 
------------------------------------------------------------------
 
The address of a points to 02A62208h, and the address of B is 02A62208h. What does this mean when B is created. the net mechanism must first look for whether the memory address of this string exists in the memory. If yes, It is pointed to and not created.

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.