you will get new objects. Right? So the hashCode of these new objects are different. So when you use these objects in contain method as key of elements jvm can not find the correct bucket of memory for searching key.
For fixing this issue you can override equal and hashCode methods in your class.
Note that the String is the best candidate for key in map.
👍👍 + I modified my objects myself. I didn't know modifying them cause the m to get lost in hashMap.
Обсуждают сегодня