I believe that most people will not go with the String class's INTERN method, open the Source code of the String class. This is a local method. It is as follows: public native string in (); document tells us that the method returns a string object's internal Chemical reference: Maintain an object pool of an initial empty string, when the INTERN method is called, if this equal string object is included in the object pool, returns an instance in the object pool, otherwise adding a string Go to the object pool and return the reference to the string. How come to see this method from the perspective of the program, we assume that there are two strings S1, S2, when S1.Equals (S2), s1.intern () == s2.intern (), that is, these two Strings are used in memory in memory. A string defined in the Java language specification and a string of the string of string and more generally constant expressions is internalized so that they share the same instance. We tried the following code
String S1 = "Hello, Java Free People";
String S2 = "Hello," "Java Free People";
System.out.println (S1 == S2);
System.out.println (S1.Intern () == S2.Intern ());
This code will print two TRUE, that is, strings S1 and S2 are shared the same instance. However, the premise is that although the expression is used, it must be constant in the expression. Of course, I still don't think of this method, but it is aware of some understanding of the internal organizational structure of the Java virtual machine. At the same time, it can understand how to solve these strings when we use the string constant. The memory occupied. It is very strange that INTERN method actually told in JBuilder 2005 to be an undefined method, which is normal in Eclipse.