If you know that your HashMap will only contain say, 20 elements, then you would be prudent to initialize your HashMap like this:
Map myMap = new HashMap(20, 1.0f);
This will cause the HashMap to create an array internally with room for 20 elements
Originally posted by Thomas Paul:
The HashMap uses the number generated by the hashcode() method. So if you override the equals method then you must override the hashcode() method otherwise you could have equal objects that are not recognized as equal by the hashmap. The default behavior is to generate a hash code based on the address which works with the default behavior of the equals method.