intermediateCollections Framework

What are the two mandatory rules for overriding hashCode(), and what breaks if you only override equals()?

Equal objects (per equals()) must have equal hash codes, and a hash code must stay consistent within one JVM run. If you override equals() without hashCode(), logically equal objects can land in different HashMap buckets, making get() fail to find entries that should match.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to When would you use TreeMap or LinkedHashMap over a plain HashMap? →← Back to all Core Java questions