Menu

1 / 2

Java Questions on Collections

DEV Community·Tapas Pal·6 months ago
#5IAKdSjP
#java#interview#beginners#career#enter
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 .…

Continue reading — create a free account

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