The string class is a special class in Java, the final class in string, and the value of a string cannot be duplicated. So there is a string pool in the Java VM (virtual machine) that is dedicated to storing strings. If you encounter string a= "Hello" (note that there is no new, not creating a string), the system looks for "Hello" in the string pool, and there is no "hello" in the string pool, then the system saves the string to the string pool and then "Hello" The address in the string pool returns a. If the system encounters a string b= "Hello" again, the system can find "Hello" in the string pool. The address is returned to B, where A and B are the same.
String a= "Hello";
System.out.println (a== "Hello");
The return value of the system is true.
1 PackageTomtext;2 3 Public classtomtext_36 {4 Private intDay ;5 Private intmonth;6 Private intYear ;7 PublicTOMTEXT_36 (intDintMinty) { 8day=D;9Month=m;TenYear=y; One } A Public voidSetDate (intDintMinty) { -day=D; -Month=m; theYear=y; - } - Public voidprintdate () { -System.out.println ("Today is" +year+ "year" +month+ "month" +day+ "Day"); + } - + Public Static voidMain (string[] args) { ATomtext_36 t=NewTOMTEXT_36 (3,4,2004); at t.printdate (); -T.setdate (4, 5, 2018); - t.printdate (); - - } - in}
The string class is a special class in Java