Code on
Public class JavaTest1 {public static void main (String [] agrs) {int a = 100; int B = 100; int c = B; string str1 = new String ("java"); String str2 = new String ("java"); String str3 = str2; if (a = B) {System. out. println ("a = B");} else {System. out. println ("! = B ");} if (B = c) {System. out. println (" B = c ");} else {System. out. println (" B! = C ");} if (str1 = str2) {System. out. println (" str1 = str2 ");} else {System. out. println (" str1! = Str2 ");} if (str2 = str3) {System. out. println (" str2 = str3 ");} else {System. out. println (" str2! = Str3 ");} if (str1.equals (str2) {System. out. println ("str1 equals str2");} else {System. out. println ("str1 doesn't equal str2");} if (str2.equals (str3) {System. out. println ("str2 equals str3");} else {System. out. println ("str2 doesn't equal str3 ");}}}
Analysis: There are two methods for comparing objects. They are the "=" operator and the equals () method, the "=" operator is used to compare whether the memory address values of two objects are equal. The equals () method is used to compare whether the content of the two objects is consistent.