java字符串相等是用==吗
eclipse里对字符串==是怎么定义的
为什么我有时候if (aaa=="abc")为true,有时候调试的时候就过不去,必须.equals
是怎么定义的
[解决办法]
String
public boolean equals(Object anObject) {
if (this == anObject) {
return true;
}
if (anObject instanceof String) {
String anotherString = (String) anObject;
int n = count;
if (n == anotherString.count) {
char v1[] = value;
char v2[] = anotherString.value;
int i = offset;
int j = anotherString.offset;
while (n-- != 0) {
if (v1[i++] != v2[j++])
return false;
}
return true;
}
}
return false;
}