String s1 = "ABC"//1 object constant area
String s2=new String("abc");//2 objects, 1 constant area, 1 heap space

String s3=s1+s2; // if the following line of code does not have s3, do not use s3
System.out.println(s3); S3=s1+s2 creates a String object

String s4="xyz"+"123";// The official compiler has 1 object "xyz123" in the constant area

S6 S7 does not create a new object
String s5 = new String();//2 objects, one in constant area, one in heap space, no hash assignment, no need to recalculate hash value when using map later
String s6 = new String("");// Two objects, one in the constant area and one in the heap space, are assigned a hash
String s7 = "";//1 object in the constant area

String s8 = “panda”;
String s9 = new String("panda");// The string needs to be traversed
String s10 = new String(s8);S9 and S10 both point to the same underlying layer
Filed filed = String.class.getDeclaredFiled("value");
field.setAccessible(true);
char[] chars = (char[])filed.get(s8);
char[1] ='x';
// both s9 and S10 will become pxnda;

String s12=s1+s2+s3+s4;
String s13=s1.concat(s2).concat.(s3).concat(s4);
// Add the underlying principle


// When the string length is less than 10 digits, use hashcode when comparing equals;
s1.hashCode()==s2.hashCode();

Copy the code