- 比較兩個字符串時
使用s.equals(t) "hello".equals(t) "hello".equalsIgonoreCase("Hello")
拒絕使用==
java中字符串存儲更像C++中指針而不是數組
String t = "Hello";
if (t == "Hello")//也許是true
if (t.substring(0, 3) == "Hel")//也許是false,因為位置不同了
s.equals(t) "hello".equals(t) "hello".equalsIgonoreCase("Hello")
==
String t = "Hello";
if (t == "Hello")//也許是true
if (t.substring(0, 3) == "Hel")//也許是false,因為位置不同了