#How would I compare HashMap keys with .equals() instead of ==?

11 messages · Page 1 of 1 (latest)

quartz crown
#

HashMap.getOrDefault compares keys with == instead of .equals, is there an equivalent method or something else I could use to compare the keys with .equals() instead?(I assumed it was .equals and would have to recode about half my project if there isnt a workaround)

brisk lionBOT
#

This post has been reserved for your question.

Hey @quartz crown! Please use /close or the Close Post button 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.

quartz crown
#

Specifically looking at the method .getOrDefault uses, .getNode

vagrant stream
#

So basically it compares keys using their hashCode methods

quartz crown
quartz crown
vagrant stream
#

Yeah, you will have to override this method in your classes

#

If your are using IntelliJ it can do it for you

quartz crown
#

Ok Ty