0% found this document useful (0 votes)
5 views5 pages

Venkatesh Cbit

Uploaded by

sundarmatsa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Venkatesh Cbit

Uploaded by

sundarmatsa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Title: Understanding equals() and HashCode() in Java

What is equals()
Method?

Purpose:
Compares two objects for logical equality.

Default Behavior:
Defined in object class.
compares objects references(memory location).
What is hashCode()
Method?
•Returns an integer hash value used by hash-based collections like HashMap, HashSet.

•Defined in object class. the default implementation uses memory address.

Syntax:

1. public int hashCode()


2. public static int hashCode(int value)
ReleationShip:
Why This Matters:

• When objects are used in collections like HashMap or HashSet, their hash codes are used to
place them in appropriate buckets for efficient retrieval.

•If a.equals(b) is true ,then a.hashCode() must equal b.hashCode().

•Always override with equals and hashcode().


THANK YOU

You might also like