所以我明白==會檢查引用號碼(內存中對象的地址)是否相等。 .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