When using a
The hash map would ask your key for a
hashCode(). If the time taken to generate a hash code is unreasonable, then insertion and retrieval times for such objects would be high. Take
java.net.URL for example. It's hashcode method performs a DNS lookup. Such objects would not make good keys for a hash map.
There is no universal answer to which is the best key, since there is no best key. The best key for use in your hash map is one that you need for retrieval. Just make sure the key's
hashCode() is quick and uses the
int space appropriately.