1

I understood, we need to implement hashcode for hashing based collections. I got upto this point but I am thinking if there are any other uses of hashcode in Java than this one. Is it something, for hashing collections, this hashcode method is invented specifically in Java?

Thanks in advance.

  • 2
    it has usages besides coupling with `equals` in collections, for example, you can log the hash of long payloads, to search for duplicates (treating it like checksum), etc. – ShaharT Jun 19 '22 at 18:13
  • 2
    And no, this is not invented specifically for / in java. As you say it is primarily for hashing based collections and basically all languages that have those have some way of letting you provide a custom hash implementation, does not matter if you call it `hashCode`, `hash`, `Hashable`, `__hash__`, ... – luk2302 Jun 19 '22 at 18:15

0 Answers0