【发布时间】:2010-10-10 07:48:08
【问题描述】:
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));
// 输出
真的
真的
假
真的
如果所有三个字符串都具有相同的内容,为什么不是所有字符串在内存中的位置都相同?
【问题讨论】:
-
这是 Java 还是 C#。您问题的答案似乎取决于语言。您可能希望相应地标记它。
-
这不是重复的。这个问题更多的是关于实习字符串而不是比较它们。
-
我想最后的评论是没有意义的,除非我提到我回滚了一个编辑,说这个问题是另一个问题的重复。如果您不同意,请随时添加链接并投票关闭。