public class Demo1 {public static void main (string[] args) {String str1 = "Hello"; String str2 = "Hello"; String str3 = new String ("Hello"); String STR4 = new String ("Hello"); System.out.println ("Str1==str2?") + (STR1==STR2)); True System.out.println ("Str2==str3?") + (STR2==STR3)); FalseSystem.out.println ("Str3==str4?") + (STR3==STR4)); FalseSystem.out.println ("Str3.equals (str2)?" + (Str3.equals (STR4))); true//is a string class that overrides the Equals method of object, comparing the contents of two string objects with consistency. the "= =" compares the memory address of two objects when comparing data of reference data types, and the Equals method is also the memory address of two objects by default. }}
Run results
Str1==str2?true
Str2==str3?false
Str3==str4?false
Str3.equals (str2)? True
Text Explanation:
Graphic:
Compare string contents with equals (), compare addresses with = =
AC Penguin: 654249738, and self-taught Exchange group: 517284938
Java_se basic--61. String entry