contentEquals与equals区别?
解决方案 »
- hashMap 线程安全问题
- 请教!急死我了。。。
- XML 解析
- 求购Java(C/S)富客户端框架
- swing里的button,单击打开jsp
- 怎样把bean:write 的值赋给一个变量
- Could not instantiate bean class [com.zhi.base.BaseAction]: Constructor threw ex
- 请帮我看一下这段代码为什么连不上数据库。。。(I'm 菜鸟)
- 一个很麻烦的问题,求救啊!
- 求教
- 小白求助!
- spring security找不到http://www.springframework.org/schema/security 命名空间
当且仅当此 String 表示与指定序列相同的 char 值时,才返回 true。
boolean contentEquals(StringBuffer sb)
当且仅当此 String 表示与指定的 StringBuffer 相同的字符序列时,才返回 true。
equals(Object anObject)
比较此字符串与指定的对象。
有自己的理解吗?
public boolean contentEquals(StringBuffer sb) {
synchronized(sb) {
return contentEquals((CharSequence)sb);
}
}public boolean contentEquals(CharSequence cs) {
if (count != cs.length())
return false;
// Argument is a StringBuffer, StringBuilder
if (cs instanceof AbstractStringBuilder) {
char v1[] = value;
char v2[] = ((AbstractStringBuilder)cs).getValue();
int i = offset;
int j = 0;
int n = count;
while (n-- != 0) {
if (v1[i++] != v2[j++])
return false;
}
}
// Argument is a String
if (cs.equals(this))
return true;
// Argument is a generic CharSequence
char v1[] = value;
int i = offset;
int j = 0;
int n = count;
while (n-- != 0) {
if (v1[i++] != cs.charAt(j++))
return false;
}
return true;
}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;
}希望对你有帮助