#How would I compare HashMap keys with .equals() instead of ==?
11 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @quartz crown! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Specifically looking at the method .getOrDefault uses, .getNode
HashMap does NOT compare keys with "==". It compares their hashes, hence the name
So basically it compares keys using their hashCode methods
Ah ok, I saw == and assumed that’s why my code wasn’t working
So if I add that to my class it’ll work fine?
Yeah, you will have to override this method in your classes
If your are using IntelliJ it can do it for you
Ok Ty