public boolean equals(Object anObject) {
//1.
if (this == anObject) {
return true;
}
//2.
if (anObject instanceof String) {
String anotherString = (String)anObject;
int n = value.length;
//3.
if (n == anotherString.value.length) {
char v1[] = value;
char v2[] = anotherString.value;
int i = 0;
//4.
while (n-- != 0) {
if (v1[i] != v2[i])
return false;
i++;
}
return true;
}
}
return false;
}
equals用于比较两个字符串对象是否相等
1.比较引用是否相等
2.确认是否字符串
3.长度是否相等
4.每个字符是否相等