String str = new String("hello");
String str2 = new String("hello");
String str3 = "hello";
System.out.println(str == str2); // false
System.out.println(str.equals(str2)); // true
String默认重写了equals方法,用于判断引用字符串是否相同,而不是只判断地址值是否相同
String str = new String("hello");
String str2 = new String("hello");
String str3 = "hello";
System.out.println(str == str2); // false
System.out.println(str.equals(str2)); // true
String默认重写了equals方法,用于判断引用字符串是否相同,而不是只判断地址值是否相同