i have created a hashmap with Color Objects as keys. My source code looks like this:
HashMap<Color,Integer> hm = new HashMap<Color,Integer>();
Now i would like to check if there is already a Color Object as a key in the HashMap. So i tried this:
if (hm.get(colorObject) != null){
Unfortunately it returns false, although the Color is the same. I print the color in the console and it is always java.awt.Color[r=254,g=0,b=0]
. I also tried the method containsKey
from HashMap
.
So what is wrong? How can i check if there is an Object in the hashmap?