Comparison between the equals method of String in java and "=", stringequals
Package stringTest; public class StringDemo {public static void main (String [] args) {// The strings defined in the following two methods are different String s1 = new String ("abc"); String s2 = "abc"; String s3 = "abc "; // s2 and s3 point to the same region in the constant pool/*** equals method in the String class, and rewrite the equals method in the Object. * This method is used to determine whether the String is the same, not the address of the comparison string **/System. out. println (s1.equals (s2); // trueSystem. out. println (s2.equals (s3); // trueSystem. out. println (s1.equals (s3); // true // "=" is the address used to compare string objects. System. out. println (s1 = s2); // falseSystem. out. println (s2 = s3); // trueSystem. out. println (s1 = s3); // false }}