重写Java String类的equals()方法

</pre><br /><pre name="code" class="java">
/*重写Java String类的equals()方法*/
public boolean equals(Object anObject){
if(this==anObject){
return true;
}
if(anObject instanceof String){
String anotherString=(String)anObject;
int n=value.length;
if(n==anotherString.value.length){
char v1[]=value;
char v2[]=anotherString.value;
int i=0;
while(n--!=0){
if(v1[i]!=v2[i])
return falsel
i++l
}
return true;
}
}
return false;
}
展开阅读全文

没有更多推荐了,返回首页