请各位大虾帮我解决一个问题,如何讲字符串的hash值计算出来.谢谢了。
解决方案 »
- 救命关于打jar包的问题 好几个文件
- 用Java语言开发,可是却一直连接不上在本地计算机内安装的oracle数据库,请高手进来详阅,帮帮忙,快急疯了,谢谢各位了!!!!
- HashTable中不用键值就取出数据吗?
- JComboBox 事件处理问题
- JPanel里怎么插入一张图片?已知图片路径
- J2EE的人才请到这里 诚聘J2EE项目经理
- 别人写的包中的文件(源文件和class文件)要在jbuilder下导入应该分别放在jbuilder下的什么目录?
- 不太明白线程控制中的yield(),请高手给小弟见解一下,最好带例子?
- 请问那里有比较好的java写的文字编辑(就好象word)那样的源程序呀?sun的例子除外!
- tomcat异常,哪位大神给说说红色字体的异常的解决方法
- 关于16进制的一个问题,急急!!大家来帮帮忙
- 为什么我最大化一下才能显出这些Button?请高手解决。
楼主【shuhan1029】截止到2008-07-02 03:07:58的历史汇总数据(不包括此帖):
发帖的总数量:0 发帖的总分数:0
结贴的总数量:0 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:0 未结的总分数:0
结贴的百分比:---------------------结分的百分比:---------------------
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
int hash = s.hashCode();
中的源码
公式:s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] /**
* Returns a hash code for this string. The hash code for a
* <code>String</code> object is computed as
* <blockquote><pre>
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
* </pre></blockquote>
* using <code>int</code> arithmetic, where <code>s[i]</code> is the
* <i>i</i>th character of the string, <code>n</code> is the length of
* the string, and <code>^</code> indicates exponentiation.
* (The hash value of the empty string is zero.)
*
* @return a hash code value for this object.
*/
public int hashCode() {
int h = hash;
if (h == 0) {
int off = offset;
char val[] = value;
int len = count; for (int i = 0; i < len; i++) {
h = 31*h + val[off++];
}
hash = h;
}
return h;
}