我想澄清一下我是否理解正确:
== - >是参考比较,即两个对象都指向相同的内存位置.equals() - >计算对象中值的比较我的理解是正确的吗?
String s1 = "BloodParrot is the man";
String s2 = "BloodParrot is the man";
String s3 = new String("BloodParrot is the man");
System.out.println(s1.equals(s2));
System.out.println(s1 == s2);
System.out.println(s1 == s3);
System.out.println(s1.equals(s3));
Run Code Online (Sandbox Code Playgroud)
//输出
真
真
假
真
如果所有三个字符串具有相同的内容,为什么所有字符串都没有在内存中相同的位置?