PrepZone Logo
PrepZone
Back to Java

Java · Medium

Why must equals() and hashCode() be consistent?

JavaCollections

Answer preview

HashMap/HashSet contract — These collections first use hashCode() to find the bucket, then equals() to find the exact match within the bucket.…