Menu

Post image 1
Post image 2
1 / 2
0

Java Questions on Collections

DEV Community·Tapas Pal·21 days ago
#5IAKdSjP
Reading 0:00
15s threshold

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 . put ( 103 , "Alex" ); Enter fullscreen mode Exit fullscreen mode Now let us understand internally what happens.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More