I have a class Car:
public class Car{
final int uniqueId;
Car(int id)
{
uniqueId=id;
}
}
I have to store this as key in a HashMap
. The max cars will be 1000. I have to decide the hashCode for this. What would be an efficient hashCode implementation for this? So the right number of buckets are formed.
The IDE generated:
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ID;
return result;
}
But it will generate a unique hashcode for each value. So it does not seems right