W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
該方法確定調(diào)用方法的? Number
? 對象是否等于作為參數(shù)傳遞的對象。
比較兩個(gè)相等的日期。 當(dāng)且僅當(dāng)參數(shù)不為?null
?并且是一個(gè) ?Date
? 對象時(shí),結(jié)果才為真,該對象表示與此對象相同的時(shí)間點(diǎn),以毫秒為單位。
因此,當(dāng)且僅當(dāng)? getTime
?方法為兩者返回相同的 ?long
? 值時(shí),兩個(gè)?Date
?對象才相等。
public boolean equals(Object obj)
?obj
?- 要與之比較的對象。
如果參數(shù)不為空,并且是同一類型且具有相同數(shù)值的對象,則方法返回?True
?。
下面是一個(gè)使用這個(gè)方法的例子 -
class Example { static void main(String[] args) { Integer x = 5; Integer y = 10; Integer z = 5; //Comparison against an Integer of different value System.out.println(x.equals(y)); //Comparison against an Integer of same value System.out.println(x.equals(z)); } }
當(dāng)我們運(yùn)行上面的程序,我們將得到以下結(jié)果 -
false true
class Example {
static void main(String[] args) {
Date olddate = new Date("05/11/2015");
Date newdate = new Date("05/11/2015");
Date latestdate = new Date();
System.out.println(olddate.equals(newdate));
System.out.println(latestdate.equals(newdate));
}
}
當(dāng)我們運(yùn)行上述的程序,我們將得到以下結(jié)果 -
true
false
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: