Internal Working of HashMap
Learn Internal Working of HashMap (Internal Working, Collection Framework) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
The big idea A HashMap is an array of buckets . To store or find a key, Java turns the key into a number (the hash code ), turns that number into an array index , and goes straight to that bucket. That is why get and put take about the same time whether the map holds 10 entries or 10 million. The array is called table ; each slot is a bucket holding a chain of Node objects (key, value, hash, next). Default capacity 16 buckets, load factor 0.75 : when more than 12 entries exist the table doubles . Two different keys can land in the same bucket: a collision . They share a linked list there....