I often auto-generate an class's hashCode()
method using IntelliJ IDEA and typically the method takes the form:
result = 31 * result + ...
My question is what is the purpose of multiplying by 31? I know this is a prime number but why pick 31 specifically? Also, if implementing a hashCode()
for a particularly small / large dataset would people approach this problem differently?