As Map Keys or Map Values? As Map Values, you don't have to do anything special (though equals is usually a good idea anyways). As Map Keys you want to make sure they fit the particular implementation's idea of equality - for HashMap that means hashcode and equals, like you mentioned, but for TreeMap it might mean compartTo instead of hashcode. Also, the Key should be immutable to make sure it can be found in the proper place when it is required.
For Map values, you don't have to do anything special, as Steve and William already said.
For Map keys, you have to have properly implemented hashCode() and equals() methods, and there's one more important thing: once you've used an object as a key in a HashMap, you should not change the member variables in the object in a way that would change the result of the hashCode() method. The way hash-based collections store objects is based on the hash code, so if the hash code changes then the collection will not work properly anymore. It's a good idea to make the POJO class immutable to ensure that you can't change the content of the object.
Jayesh A Lalwani wrote:Ok because the answer has been given multiple times, I will extend the answer because I'm a smartass like that If you intend to serialize your Map, both the key and value have to be serializable.
To add to that, the original question also didn't mention that it was a hash map. So...
In the case of a TreeMap, with a comparator, then nothing needs to be done for both the map key or map value.
In the case of a TreeMap, without a comparator, then nothing needs to be done for the map value. For the map key, it needs to support the comparable interface. It also *should* support the equals() method, but interestingly, it is not necessary -- as consistency between equals() and compareTo() methods are not checked.