Java Reference
In-Depth Information
public HashMap(int initialCapacity, float loadFactor)
Creates a new HashMap with initialCapacity hash buckets and
the given loadFactor , which must be a positive number.
public HashMap(int initialCapacity)
Creates a new HashMap with the given initialCapacity and a de-
fault load factor.
public HashMap()
Creates a new HashMap with default initial capacity and load
factor.
public HashMap(Map<? extends K, ? extends V> map)
Creates a new HashMap whose initial mappings are copied from
map . The initial capacity is based on the size of map ; the default
load factor is used.
The internal table used by a hash map consists of a number of buckets,
initially determined by the initial capacity of the hash map. The hash
code of an object (or a special hashing function used by the hash map
implementation) determines which bucket an object should be stored
in. The fewer the number of buckets, the more likely that different ob-
jects will get stored in the same bucket, so looking up the object will
take longer because the bucket has to be examined in detail. The more
buckets there are, the less likely it is that this will occur, and the lookup
performance will improvebut the space occupied by the hash map will
increase. Further, the more buckets there are, the longer iteration will
take, so if iteration is important you may want to reduce the number of
bucketsthe cost of iteration is proportional to the sum of the hash map's
size and capacity. The load factor determines when the hash map will
automatically have its capacity increased. When the number of entries
in the hash map exceeds the product of the load factor and the current
capacity, the capacity will be doubled. Increasing the capacity requires
 
Search WWH ::




Custom Search