-
== : Compares the values of the two variables themselves, that is, the first address in memory of the two objects. Object (in Java, it is the first address in memory the starting address of the store, it behind the address is used to deposit it contains the address of each attribute, so memory will use more memory blocks to store all parameters of the object, and through the first address. Then you will find the object, which can find the object attributes)
-
Equals: Compares whether the contents of a string are the same.
-
Case code
public class test { public static void main(String[] args) { String s1 = "dzm"; String s2 = "dzm"; String s3 = new String("dzm"); System.out.println(s1 == s2); System.out.println(s1 == s3); system.out. println(s1 == s3); // false // s1 Contains s3 system.out.println (s1.equals(s2)); // false // s1 contains s3 system.out.println (s1.equals(s2)); // true // s1 Contains s3 system.out.println (s1.equals(s3)); // true } }Copy the code