Package com.demo02;
public class Testobject {
/**
* @param args
*/
/*
* 1, the object class is the root class, inside the definition of = = and equals the same role, are compared to the reference address
* 2, and the string immutable class overrides the Equals method inside.
* = = is the comparison reference address, equals is the comparison content
* 3. What string pool is in the string class, and for a string object that can be shared, the lookup in the pool appears
* Whether the same string content exists (the same string), and if so, returns directly instead of creating a new
* String object to reduce memory consumption
*
*
* */
public static void Main (string[] args) {
TODO auto-generated Method Stub
Testobject T1 = new Testobject ();
Testobject t2 = new Testobject ();
System.out.println (T1==T2);//false
System.out.println (T1.equals (T2));//false
string S1 = new String ("abc");
String s2 = new String ("abc");
System.out.println (S1==S2);//false
System.out.println (s1.equals (S2));//true
String s3 = "Hello";
String s4 = "Hello";
System.out.println (S3==S4);//true
System.out.println (S3.equals (S4));//true
}
}
The difference between = = and equals in Java