public boolean equals(Object anObject) {
//判断当前对象和传入对象引用是否相同,如果相同则返回true
if (this == anObject) {
return true;
}
/*
判断传入对象是否String类型,如果不是返回false如果是则
继续
*/
if (anObject instanceof String) {
String anotherString = (String)anObject;
int n = value.length;
/*
判断当前对象和传入对象的长度是否相同,如果不同
返回false如果相同则继续
*/
if (n == anotherString.value.length) {
char v1[] = value;
char v2[] = anotherString.value;
int i = 0;
/*
循环比较两个char数组是否相同,如果有不同则返回false
*/
while (n-- != 0) {
if (v1[i] != v2[i])
return false;
i++;
}
//循环比较完如果char数组没有不同字符则返回true
return true;
}
}
return false;
}
04-06
2014
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-20
208
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交