I have a class like this
Class A{
private String string1;
private String string2;
..
..
private String string19;
}
Some of the strings may be empty.
I want to get an hash/identifier (string or number) for the instances of this class.
I can use hashCode but i don’t know if i can get some collision, i have a lot of instances of this class (about 4-5 million).
I need a fast way to get this hash.
Thanks for the help.
You could write a custom
hashCodemethod that uses a slightly altered version of thehashCodealgorithm in the String class. From the Oracle documentation, the StringhashCodeis computed as follows:You could implement a modified version where you compute
nover all the String objects in your class. This way you are not wasting space and time creating a concatenated String to do the same. In some circumstances this might be fine, but with 4-5 million objects, you probably want to avoid that much churn.Source: http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#hashCode%28%29