所以我明白==会检查引用号码(内存中对象的地址)是否相等。 .equals()检查对象的内容。比较java中使用==的字符串vs .equals
String s = "test";
String s2 = "test";
我创建了两个不同的字符串对象,但还没有,我得到如下:
s == s2; //true, I dont know why, aren't s and s2 two different objects with
different internal values
s.equals(s2); //true, which I understand
这已在[此线程]中详细解释(http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java)。 – eis 2014-12-07 18:10:38