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.