Creating a hash from several Java string objects
hash, hashcode, java, md5, sha
Solution
Here is the simple implementation using Objects class available from Java 7.
@Override
public int hashCode()
{
return Objects.hash(this.variable1, this.variable2);
}
Problem
What would be the fastest and more robust (in terms of uniqueness) way for implementing a method like ``` public abstract String hash(String[] values); ``` The `values[]` array has 100 to 1,000 members, each of a which with few dozen characters, and the method needs to be run about 10,000 times/sec on a different `values[]` array each time. Should a long string be build using a `StringBuilder` buffer and then a hash method invoked on the buffer contents, or is it better to keep invoking the hash method for each string from `values[]`? Obviously a hash of at least 64 bits is needed (e.g., MD5) to avoid collisions, but is there anything simpler and faster that could be done, at the same quality? For example, what about ``` public String hash(String[] values) { long result = 0; for (String v:values) { result += v.hashCode(); } return String.valueOf(result); } ```