Package Object;class value{int i;} public class E08_statictest {public static void main (string[] args) { integer n1= new integer (n); Integer n2= new integer (n); int n3=12; int n4=12; System.out.println (N1==N2);//Compare the object's reference rather than the object's content System.out.println (n1!=n2); System.out.println (N3==N4); System.out.println (N3!=N4); System.out.println (N1.equals (N2)); Value n5=new value (); Value n6=new value (); n5.i=n6.i=67; System.out.println (N5.equals (N6));//Compare the object's reference to the object's contents}/* output:falsetruetruefalsetruefalse*///:~
When comparing basic types, such as int,double (N3,N4), etc. ==,! = Compare the size between the two, but for new objects (N1,N2), you must use the Equals () method to compare the size relationship between the two objects.
For a user-created class (N5,N6), the Equals () method must be overloaded when comparing size relationships, because the default behavior of the Equals () method is to compare references rather than to compare the contents of objects.
Most Java class libraries implement the Equals () method to compare the contents of an object, rather than a reference to a comparison object.
relational operators in Java