0% found this document useful (0 votes)
7 views

New Microsoft Word Document (4)

HashMap is a fast, non-thread-safe key-value store in Java that uses hashing for average O(1) operations. It handles collisions through chaining and treeification, and automatically resizes when the load factor exceeds 0.75. Keys must be unique, while values can be duplicated, and custom objects as keys require overriding hashCode() and equals().

Uploaded by

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

New Microsoft Word Document (4)

HashMap is a fast, non-thread-safe key-value store in Java that uses hashing for average O(1) operations. It handles collisions through chaining and treeification, and automatically resizes when the load factor exceeds 0.75. Keys must be unique, while values can be duplicated, and custom objects as keys require overriding hashCode() and equals().

Uploaded by

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

 HashMap stores key-value pairs and allows fast

retrieval, insertion, and deletion using a hash


table1235.
 Internal Structure:
 Uses an array of buckets (each bucket is a
linked list or, for high collision, a balanced
tree)13.
 Each key’s hashCode() determines the bucket
index13.
 Collision Handling:
 If multiple keys hash to the same bucket,
entries are stored in a linked list (chaining)13.
 If a bucket’s list grows too long (threshold =
8), it’s converted to a Red-Black tree for better
performance3.
 Performance:
 Average case: O(1) for put() and get()235.
 Worst case: O(n) if many collisions, but O(log
n) if treeified3.
 Load Factor & Resizing:
 Default load factor is 0.75135.
 When size exceeds (capacity × load factor), the
HashMap resizes (rehashing occurs, capacity
doubles)35.
 Key Rules:
 Keys must be unique; values can be
duplicated5.
 Allows one null key and multiple null values5.
 Not synchronized (not thread-safe by default)5.
 Custom Objects as Keys:
 Must override hashCode() and equals() for
correct behavior3.
Summary Table

Feature Details

Structure Array of buckets (linked list/tree)

Collision Handling Chaining, treeification (Red-Black tree)

Performance O(1) average, O(log n) tree, O(n) worst

Load Factor Default 0.75, triggers resizing

Nulls 1 null key, multiple null values allowed

Thread Safety Not synchronized

Key Uniqueness Keys unique, values can repeat

One-liner:
HashMap in Java is a fast, non-thread-safe key-value
store using hashing, with average O(1) operations,
collision handling via chaining/tree, and automatic
resizing based on load factor135.

You might also like