I have a Color class that I\'m putting in the hashmap. I\'d like to call containsKey
on the hashmap to ensure whether the object is already present in the hashm
Your custom class Color
should override equals()
and hashcode()
methods to achieve what you want.
When you are using custom objects as keys for collections
and would like to do lookup using object, then you should properly override equals()
and hashcode()
methods.
Also read:
Overriding equals and hashCode in Java