---String---
equals in Stringpublic 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;
}
equals in Object public boolean equals(Object obj) {
return (this == obj);
}
System.out.println(new String("aa").equals(new String("aa"))); //true
System.out.println(new String("aa") == new String("aa")); //false
System.out.println("aa".equals("aa")); //true
System.out.println("aa" == "aa"); //true
posted on 2007-05-23 22:35
Jcat 阅读(317)
评论(0) 编辑 收藏 所属分类:
Java