C.4.3 The HashMap class

advertisement
531
The inherited iterator operation returns an iterator that will visit the sorted map's
entries in ascending order by key. The fact that the map is sorted has no effect on the
behavior of the other inherited operations.
The sorted-map-specific f irstKey and lastKey operations return the least and
greatest keys, respectively, of the sorted map.
The sorted-map-specific tailMap, headMap, and subMap operations each returns
a map view of part of the sorted map, defined respectively by a given least key, a given
greater key, or both.
By default, the sorted map's keys must all be Comparable objects, and are sorted in
their natural ordering. However, if the sorted map has an associated comparator, its keys
are sorted in the ordering imposed by that comparator.
C.4.3 The HashMap class
The HashMap class (Program C.I3) implements the Map interface. The map is represented by an open-bucket hash table, whose number of buckets defines the current
capacity of the map. The capacity is increased automatically whenever a predetermined
maximum load factor (0.75 by default) is reached. The implementation uses a hash
function expressed in terms of the keys' hashCode operation.
public class HashMap
implements Map, Cloneable, Serializable {
/ / Each HashMap object is a map whose keys and values are objects.
/ / This map is represented by an open-bucket hash table, with a variable
/ / capacity and a fixed maximum load factor.
/ / / / / / / / / / / / Constructors / / / / / / / / / / / /
public HashMap ()
{...}
/ / Construct an empty map.
public HashMap (int cap) { ... }
/ / Construct an empty map, whose initial capacity is cap, and whose
/ / maximum load factor is 0.75.
public HashMap (int cap, float maxLoad)
{ ... }
/ / Construct an empty map, whose initial capacity is cap, and whose
/ / maximum load factor is maxLoad.
public HashMap (Map that)
{ ... }
/ / Construct a map containing the same entries as that.
/ / Accessors and transformers specified by the above interfaces.
Program C.13
The HashMap class.
Download