11.0k views
5 votes
What advantage does HashMap have over TreeMap?

a) Faster key lookup
b) Sorted keys
c) Better memory usage
d) No key-value pairs

User Georstef
by
8.6k points

1 Answer

1 vote

Final answer:

HashMap provides faster key lookup compared to TreeMap.

Step-by-step explanation:

The advantage that HashMap has over TreeMap is that it provides faster key lookup. In a HashMap, the keys are not sorted, so it allows for quick access to values based on their keys. On the other hand, a TreeMap stores keys in a sorted order, which makes it useful in scenarios where you need to traverse the keys in a specific order, but it might have a slower key lookup compared to a HashMap.

User Manolito
by
8.2k points