3 回答
TA貢獻1806條經驗 獲得超8個贊
trueequals
String s = "a" + "bc"; String t = "ab" + "c"; System.out.println(s == t);
stStringst
String
TA貢獻1776條經驗 獲得超12個贊
加載包含字符串文本的類或接口可能會創建一個新的String對象(§2.4.8)來表示該文本。如果已經創建了一個字符串對象來表示該文本的前一次出現,或者在一個字符串對象上調用了String.intern方法,則可能不會發生這種情況。
這可能不會發生String
1: a := "one"
--> if(pool[hash("one")] == null) // true
pool[hash("one") --> "one"]
return pool[hash("one")]2: b := "one"
--> if(pool[hash("one")] == null) // false, "one" already in pool
pool[hash("one") --> "one"]
return pool[hash("one")]ab(a == b) && (a.equals(b)) == true.
1: a := "one"2: b := new String("one")"one"(a == b) && (a.equals(b)) == false
(a == b) && (a.equals(b))可能是 true或 false(總使用 equals比較字符串) 不要使用反射來更改背景 char[](因為您不知道是誰在使用該字符串)
添加回答
舉報
