The Java Runtime Environment has a string pool maintained by the string class. When executing the statement string STR = "ABC", first check whether the string "ABC" exists in the string pool. If yes, directly assign "ABC" to STR, if it does not exist, create a new string "ABC" in the string pool, and then assign it to Str. When executing the statement string STR = new string ("ABC"), create a new string "ABC" regardless of whether the string pool contains the string "ABC" (note: the new string "ABC" is not in the string pool), and then it is paid to Str. The efficiency of the previous statement is high, and the efficiency of the latter statement is low, because the new string occupies memory space. String STR = new string () creates an empty string, which is the same as string STR = new string. The following is an example: <br/> public class comparestring {<br/> Public static void main (string [] ARGs) {<br/> string a = new string (); <br/> string AA = ""; <br/> string AAA = new string (""); <br/> string B = new string ("ASDF"); <br/> string c = new string ("ASDF "); <br/> string d = "ASDF"; <br/> system. out. println (A = aa); <br/> system. out. println (A = aaa); <br/> system. out. println (. intern () = AA. in TERN (); <br/> system. out. println (. intern () = aaa. intern (); <br/> system. out. println (D = "ASDF"); <br/> system. out. println (B = C); <br/> system. out. println (B = D); <br/> system. out. println (B. equals (c); <br/> system. out. println (B. equals (d); <br/> B = B. intern (); <br/> system. out. println (B = C); <br/> system. out. println (B = D); <br/> C = C. intern (); <br/> system. out. println (B = C ); <Br/>}< br/> the preceding <SPAN class = 'wp _ keywordlink '> Program </span> runs as follows: <br/> false <br/> true <br/> true <br/> false <br/> true <br/> the preceding content can be verified from the running result. If you do not understand the use of the intern () method of the string class, refer to the JDK documentation: <br/> Public String intern () <br/> Returns a canonical representation for the string object. <br/> A pool of strings, initially empty, is maintained privately by the class string. <br/> when the intern method is invoked, if the pool already contains a string equal to this string object as determined by the equals (object) method, then the string from the pool Is returned. otherwise, this string object is added to the pool and a reference to this string object is returned. <br/> it follows that for any two strings S and T, S. intern () = T. intern () is true if and only if S. equals (t) is true. <br/> All literal strings and string-valued constant expressions are interned. string literals are defined in § 3. 10.5 of the Java language specification <br/> return S: <br/> a string that has the same contents as this string, but is guaranteed to be from a pool of unique strings. <br/> from the comparestring class, we can also see the difference between = and equals (): that is, = compares whether the references (that is, the memory address) of two objects are equal, equals () compares the values of two objects (that is, the values stored in the memory address) for equality. Of course, if equals () is overwritten in some classes, that is, the exception. <Br/> (the above is only a summary of individual learning. please correct me if any errors exist !)