Languages

Java - Do I need to implement equals and hash code in treemap?

6 points
Asked by:
Huzaifa-Ball
475

Java - Do I need to implement equals and hash code in treemap?

1 answer
3 points
Answered by:
Root-ssh
178180

No, you don't.

We don't need to implement equals and hashCode in key object used in TreeMap or HashSet.

TreeMap and HashSet in java works by comparing objets (that's why we have sorted order). If the key is the same than the value is overrided by new value.

Here is entire post about this topic:

0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join