posted 17 years ago
Hi ranchers,
how I understand this question:
first feature (key/value pairs)
The only collections that provide keys are maps. Maps are collections that have "map" in their name. Hashtable is also a map, but has no "map" in its name because of historical reasons.
So we can strike out all wrong answers and only
LinkedHashMap
TreeMap
HashMap
Hashtable (old synchronized version of HashMap)
remain.
second feature (Duplicate entries replace old)
true for all maps, cause duplicate keys "override" old key value pairs.
third feature (constant-time performance for add...)
TreeMap is ordered. Every time you add something, the tree has to be ordered again. And the time to do this depends if you add in the middle or at the tail. IE it depends if you add an "N" or a "Z", simply speaking.
Re-Ordering also takes place when you remove(), so we can strike TreeMap out two times.
LinkedHashMap
HashMap
Hashtable
remain.
About LinkedHashMap:
It is not ordered, just sorted (by entry time). Every time you add a pair it is just glued to the tail, should be time constant.
Bu.
all events occur in real time