Grokking Java Interview Questions
0% completed
How HashMap Stores and Finds Entries
An online grocery store keeps the stock count of 40,000 products in one HashMap, with the product name as the key. When the code calls stock.get("mango"), how many of the 40,000 keys does the map compare with "mango"? The usual answer is one, and it is rarely more than two or three.
The four questions below explain why. They cover how a key leads to one position in an array, what happens when two keys need the same position, what each operation costs, and how the map treats null and ordering.
How does a HashMap find the value for a key?
Level: Mid-level
**A `HashMap
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%