vb.net中实现java字符串的hashcode
之前在java中一直用hashcode,到了VB.net中却找不到类似的用法了,只好自己实现一下了,下面就是使用VB.net编写的hashcode方法:
Private Function hashcode(ByVal str As String)
Dim chars() As Char = str.ToCharArray
Dim n As Long = chars.Length
Dim result As Long = 0
Dim i As Long = 0
For i = 0 To n - 1 Step 1
result += (31 ^ (n - 1 - i)) * AscW(chars(i))
Next
hashcode = result
End Function
后边附上网上找到java的hashcode方法:
public int hashcode(String str){
char[] chars;
chars = str.toCharArray();
int n = chars.length;
int result=0;
for (int i = 0;i<n ;i++ )
{
result+=java.lang.Math.pow(31,n-1-i)*chars[i];
//String的hashcode算法
// API中String的hashCode()方法返回:s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
}
return result;
}
- java.lang.IllegalArgumentException: java.security.InvalidKeyException: Illegal key size(2023-12-15)
- java SimpleDateFormat处理英文3位字母月份时的注意事项(2019-11-27)
- IE浏览器javascript new date NAN bug的解决(2016-04-27)
- 清理java项目中多余的jar包(2016-03-10)
- 安卓下java连接串口进行客显控制的方法(2016-02-02)
- 卸载aliyun linux 15预装的java运行环境openjdk 1.6(2016-01-30)
- vb.net调用java axis2生成的soap webservices(2015-04-03)
- java及tomcat使用http正向代理的几种方法(2015-03-08)
- vb.net的接口定义及使用(2015-02-21)
- vb.net中自定义结构structure的定义及使用(2015-02-17)