Hash codes can be thought of as pseudo-random numbers. Statistically, with a positive int
hash code the chance of a collision between any two elements reaches 50% when the population size is about 54K (and 77K for any int
). See Birthday Problem Probability Table for collision probabilities of various hash code sizes.
Also, your idea to use Math.abs()
alone is flawed: It does not always return a positive number! In 2's compliment arithmetic, the absolute value of Integer.MIN_VALUE
is itself! Famously, the hash code of "polygenelubricants"
is this value.