HashMap
| Kind of class: | public class |
|---|---|
| Package: | com.bourre.collection |
| Inherits from: | none |
| Author: | Francis Bourre |
| Classpath: | com.bourre.collection.HashMap |
| File last modified: | Monday, 24 November 2008, 11:36:49 |
each key can map to at most one value.
The "destructive" methods contained in this interface, that is, the
methods that modify the map on which they operate, are specified to throwUnsupportedOperationException if this map does not support the
operation. If this is the case, these methods may, but are not required
to, throw an UnsupportedOperationException if the invocation would
have no effect on the map. For example, invoking the putAll(Map)method on an unmodifiable map may, but is not required to, throw the
exception if the map whose mappings are to be "superimposed" is empty.
Some map implementations have restrictions on the keys and values they
may contain. For example, some implementations prohibit null keys and
values, and some have restrictions on the types of their keys. Attempting
to insert an ineligible key or value throws an unchecked exception,
typically NullPointerException or ClassCastException.
Attempting to query the presence of an ineligible key or value may throw an
exception, or it may simply return false; some implementations will exhibit
the former behavior and some will exhibit the latter. More generally,
attempting an operation on an ineligible key or value whose completion
would not result in the insertion of an ineligible element into the map may
throw an exception or it may succeed, at the option of the implementation.
Such exceptions are marked as "optional" in the specification for this
interface.
Many methods in Collections Framework interfaces are defined
in terms of the === operator. For example, the
specification for the containsKey( key : Object )method says: "returns true if and
only if this map contains a mapping for a key k such thatkey === k." This specification should
not be construed to imply that invoking HashMap.containsKeywith a non-null argument key will cause key === k to
be invoked for any key k. Implementations are free to
implement optimizations whereby the === invocation is avoided,
for example, by first comparing the hash codes of the two keys. (TheHashCodeFactory.getKey(Object) specification guarantees that two
objects with unequal hash codes cannot be equal.) More generally, implementations of
the various Collections Framework interfaces are free to take advantage of
the specified behavior of underlying Object methods wherever the
implementor deems it appropriate.
Summary
- clear : void
- Removes all of the mappings from this map (optional operation).
- isEmpty : Boolean
- Returns true if this map contains no key-value mappings.
- containsKey (key:*) : Boolean
- Returns true if this map contains a mapping for the specified
- containsValue (value:*) : Boolean
- Returns true if this map maps one or more keys to the
- put (key:*, value:*) : *
- Associates the specified value with the specified key in this map
- get (key:*) : *
- Returns the value to which the specified key is mapped,
- remove (key:*) : *
- Removes the mapping for a key from this map if it is present
- size : Number
- Returns the number of key-value mappings in this map.
- getKeys : Array
- Returns an Array view of the keys contained in this map.
- getValues : Array
- Returns an Array view of the values contained in this map.
- toString : String
- Returns the string representation of this instance.
Constructor
HashMap
Instance methods
clear
The map will be empty after this call returns.
containsKey
true if this map contains a mapping for the specifiedkey. More formally, returns
true if and only ifthis map contains a mapping for a key
k such thatkey === k. (There can be at most one such mapping.) -
trueif this map contains a mapping for the specified
key
- {VISDOC_LINK_0}
NullPointerException— if the specified key is null
containsValue
true if this map maps one or more keys to thespecified value. More formally, returns
true if and only ifthis map contains at least one mapping to a value
v such that(value === v). -
trueif this map maps one or more keys to the
specified value
get
or
null if this map contains no mapping for the key.More formally, if this map contains a mapping from a keyk to a value v such that (key === k), then this method returns v; otherwise
it returns null. (There can be at most one such mapping.)
As this map permits null values, a return value of nulldoes not necessarily indicate that the map contains no mapping
for the key; it's also possible that the map explicitly maps the key tonull. The containsKey operation may be used
to distinguish these two cases.
- the value to which the specified key is mapped, or
nullif this map contains no mapping for the key
- {VISDOC_LINK_0}
NullPointerException— if the specified key is null
getKeys
Array view of the keys contained in this map. - an array view of the keys contained in this map
getValues
Array view of the values contained in this map. - an array view of the values contained in this map
isEmpty
true if this map contains no key-value mappings. -
trueif this map contains no key-value mappings
put
(optional operation). If the map previously contained a mapping for
the key, the old value is replaced by the specified value. (A map
m is said to contain a mapping for a key k if and only if
m.containsKey(k) would returntrue.) - the previous value associated with
key, or
nullif there was no mapping forkey.
(Anullreturn can also indicate that the map
previously associatednullwithkey,
if the implementation supportsnullvalues.)
- {VISDOC_LINK_0}
NullPointerException— if the specified key or value is null
remove
(optional operation). More formally, if this map contains a mapping
from key
k to value v such that(key === k), that mapping is removed. (The map can contain at most one such mapping.)
Returns the value to which this map previously associated the key,
or null if the map contained no mapping for the key.
As this map permits null values, then a return value ofnull does not necessarily indicate that the map
contained no mapping for the key; it's also possible that the map
explicitly mapped the key to null.
The map will not contain a mapping for the specified key once the
call returns.
- the previous value associated with
key, or
nullif there was no mapping forkey.
- {VISDOC_LINK_0}
NullPointerException— if the specified key is null
size
- the number of key-value mappings in this map
toString
- the string representation of this instance