public class CompareObject1 {public static void main (string[] args) { string str1 = new String ("Java"); String str2 = new String ("Java"); String STR3 = str2;if (str1 = = str2) {System.out.println ("str1 = = str2");} Else{system.out.println ("str1!=str2");} if (STR2==STR3) {System.out.println ("str2 = = TR3");} else {System.out.println ("str2! = Str3");}}} The open memory nodes are different, so they are not equal; the assignment must be equal.
Public classCompareObject2 { Public Static voidMain (string[] args) {String str1=NewString ("Java"); String str2=NewString ("Java"); String STR3=str2; if(Str1.equals (str2)) {System.out.println ("Str1 equals str2"); } Else{System.out.println ("Str1 not equals str2"); } if(Str2.equals (STR3)) {System.out.println ("Str2 equals TR3"); } Else{System.out.println ("Str2 not equals STR3"); }}}//compare strings for equality with equals ()
"Java Summary" string comparisons are equal