Java Reference
In-Depth Information
HashMap<K,V> Class
Package:
java.util
Ancestor classes:
Object
|
+--AbstractMap<K,V>
|
+--HashMap<K,V>
Implements interfaces:
Map<K,V>
,
Cloneable
,
Serializable
The
HashMap<K,V>
class implements all of the methods in the
Map<K,V>
interface. The only
other methods in the
HashMap<K,V>
class are the constructors.
All the exception classes mentioned are the kind that are not required to be caught in a catch
block or declared in a throws clause. All the exception classes mentioned are in the package
java.lang
and so do not require any import statement. The class
K
must implement the
equals
and
hashCode
methods.
public
HashMap()
Creates a new, empty map with a default initial capacity of 16 and load factor of 0.75. The
capacity is the number of slots in the hash table. The load factor is the percentage of capacity
before the size of the table is automatically increased.
public
HashMap(
int
initialCapacity)
Creates a new, empty map with a default capacity of
initialCapacity
and load factor of 0.75.
Throws:
IllegalArgumentException
if the initial capacity is negative.
public
HashMap(
int
initialCapacity,
float
loadFactor)
Creates a new, empty map with the specifi ed capacity and load factor.
Throws:
IllegalArgumentException
if the initial capacity or the load factor is negative.
public
HashMap(Map<?
extends
K,?
extends
V> m)
Creates a new map with the same mappings as
m
. The
initialCapacity
is set to the same
size as
m
and the
loadFactor
to 0.75.
Throws:
NullPointerException
if
m
is
null
.
public
Object clone( )
Creates a shallow copy of this instance and returns it. The keys and values are not cloned.
The remainder of the methods are the same as those described for the
Map<K,V>
interface.