Grokking Java Interview Questions
Vote

0% completed

​

TreeMap, TreeSet, and Ordering

An online grocery store keeps its prices in a HashMap, which finds the price of one product quickly. The same map cannot answer three questions that a price page must answer:

  • Which product is the cheapest?
  • Which products cost between 100 and 260 cents?
  • What is the next price above 120 cents?

A HashMap places its keys by hash code, so it would have to read every entry to answer any of them. A TreeMap keeps its keys sorted at all times and answers each one by reading a few entries

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content