W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
String obj1 = new String("xyz");
String obj2 = new String("xyz");
// If String obj2 = obj1, the output will be true
if(obj1 == obj2)
System.out.printlln("obj1==obj2 is TRUE");
else
System.out.println("obj1==obj2 is FALSE");
// It will print obj1==obj2 is False
// If String obj2 = obj1, the output will be true
默認(rèn)的, equals() 方法實(shí)際上和 “==” 在 object 類里是一樣的. 但是這個(gè)方法在每一個(gè)子類里都會(huì)被覆寫用來比較引用的內(nèi)容 (因?yàn)槊總€(gè)類都繼承了 object 類并覆寫了這個(gè)方法)
String obj1 = new String("xyz");
String obj2 = new String("xyz");
if(obj1.equals(obj2))
System.out.printlln("obj1==obj2 is TRUE");
else
System.out.println("obj1==obj2 is FALSE");
Resultat: obj1==obj2 is TRUE
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: