The so-called World article is copied, find a Java string pool of articles on the Internet, search n more than one entry, it seems to look at two articles, summarized as follows:
First look at a piece of code:
String a = "Hello";
String B = "Hello";
String c = new String ("Hello");
String d = new String ("Hello");
System.out.println (A = = B);
System.out.println (b = = c);
System.out.println (c = = d);
System.out.println (A.equals (b));
System.out.println (B.equals (c));
System.out.println (C.equals (d));
The result is true,false,false,true,true,true. The string pool is involved here. "String Pool" is the measure that Java uses to improve memory utilization: when encountering string a = "Hello"; When such a statement is made, Java will first look in the string pool for whether the string "Hello" already exists, if not, establish the string "Hello" object, then the variable a points to the address, and then encounter the statement string b = "Hello", the string pool already has " Hello ", so just let the variable B also point to this address, eliminating the hassle of redistribution. In Java, the operator "= =" for the two basic type, is to determine whether the content is the same, for two objects, it is to determine whether the address is the same, so a = = B returns True. So what about string c = new String ("Hello")? If this is the case, then the string pool will not be accessed, instead the variable C is first opened up and then the value is written to space. So a = = c returns false,c = = D also returns false. As for the Equals method of the string, because it compares the object's address to the object's value, it is not surprising that it returns true.
The Java Virtual machine has a string pool that holds almost all of the string objects. A string expression always points to an object in the string pool. A string object created with the new action does not point to an object in the string pool but you can use the Intern method to point to an object in the string pool (note: If the pool already has the same string--using the Equals method, the string in the pool is returned, or the string is first added to the pool. Back again). Two equal strings in the pool will return true if they are compared using "= =".
Java String Pool