张榆 发表于 2012-9-25 13:14
这上面就是说equals判断对象的啊
Object类中equals()方法- public boolean equals(Object obj) {
- return (this == obj);
- }
复制代码 String类中的equals()方法- 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;
- }
复制代码 你自己对比一下看看有什么不同,然后总结一下 |