Day-1
1. How does HashMap work internally?
Answer:
High-Level Internal Structure
Internally, HashMap uses:
Array + LinkedList + Red-Black Tree (Java 8+)
Internal Data Structure
transient Node < K , V >[] table ;
Enter fullscreen mode
Exit fullscreen mode
This is an array of buckets.
Each bucket stores:
single node
linked list
tree nodes
Basic Working Flow
When you do:
map . put ( key , value );
Enter fullscreen mode
Exit fullscreen mode
HashMap performs:
Calculate hashCode()
Calculate bucket index
Store value in bucket
Handle collision if needed
Step-by-Step Example
Map < Integer , String > map = new HashMap <>(); map . put ( 101 , "John" ); map . put ( 102 , "David" ); map .…