If you've used
Hashtable, you're already familiar with the general flavor of Map. (Of course Map is an interface, while Hashtable is a concrete implementation.) Here are the major differences: -
MapprovidesCollection-views in lieu of direct support for iteration viaEnumerationobjects.Collection-views greatly enhance the expressiveness of the interface, as discussed later in this lesson. -
Mapallows you to iterate over keys, values, or key-value pairs;Hashtabledid not provide the third option. -
Mapprovides a safe way to remove entries in the midst of iteration;Hashtabledid not.
Map fixes a minor deficiency in the Hashtable interface. Hashtable has a method called contains, which returns true if the Hashtable contains a given value. Given its name, you'd expect this method to return true if the Hashtable contained a given key, as the key is the primary access mechanism for a Hashtable. The Map interface eliminates this source of confusion by renaming the method containsValue. Also, this improves the consistency of the interface: containsValue parallels containsKey nicely.
No comments:
Post a Comment