简体   繁体   中英

How to generate a hash value in J2ME?

How can I generate hash value for a byte array, in J2ME?

It doesn't have to be very very secure but it should be fast.

As suggested by Josh Bloch in his Effective Java book:

public int hashCode() {
   int result = 17;
   for (int i = 0; i < array.length; i++) {
      result = 31*result + (int)array[i];
   }
   return result;
}

如果您已经对Apache Commons Lang有所依赖,则最好使用HashCodeBuilder

new HashCodeBuilder().append(bytes).toHashCode();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM