链接 https://blog.csdn.net/liyunxiangrxm/article/details/53541513
从object类来看,equal和==都是比较的对象的地址,但是在String中,equal比较的是内容是否相等,因为在String中对equal进行了重写。
源码先挂在这里
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 false;
i++;
}
return true;
}
}
return false;
}