Java's virtual machines create a separate area in memory that is used to store string objects, a memory area called a string buffer pool.
When creating a string, look for objects that do not have the same object in the string buffer pool, if the same object returns a reference to the object directly
If you do not have the same object, create the object in the string, and then return the object's reference
String a = "123";
String B = "123";
= = Compares memory addresses for equality
if (a = = b) {
SYSTEM.OUT.PRINTLN ("Output equal");
}else{
System.out.println ("unequal");
}
Two objects created
One is the object created in the 567 buffer pool
One is the object created in the object memory of new, but the address that C points to is in memory
String d = "567";
String c = new String ("567");
if (d = = c) {
System.out.println ("D and C equal");
}else{
SYSTEM.OUT.PRINTLN ("Output D and C are not equal");
}
if (D.equals (c)) {
System.out.println ("Output EQUALSD and C equal");
}else{
System.out.println ("EQUALSD and C are not equal");
}
Returns a reference to a string object in the buffer pool
c = C.intern ();
if (d = = c) {
SYSTEM.OUT.PRINTLN ("Output D and C equal");
}else{
System.out.println ("D and C are not equal");
}
String a1 = "Dogapple";
String A2 = "Dog";
String a3 = "Apple";
String A4 = a2 + A3;
SYSTEM.OUT.PRINTLN (a1 = = A4);
System.out.println (A1.equals (A2+A3));
Java string Parsing