|
|
The Department of Computer Science & Engineering
|
CSE 115
Introduction To Computer Science for Majors I
Lecture C
Lecture Notes #24
Stuart C. Shapiro
Spring, 2007
HashMap
java.util.HashMap<K,V>
is a class of structures that map one object, the key, to another
object, the value.
The most useful methods of java.util.HashMap<K,V> are:
- put(K
key, V value): Associates the specified value with the specified
key in this map.
- get(Object
key) : Returns the value to which the specified key is mapped, or
null if the map contains no mapping for this key.
Note: the equals method is used for comparison, not
==.
- remove(Object
key) : Removes the mapping for this key from this map if present.
- keySet():
Returns a set of the keys contained in this map.
- values():
Returns a collection of the values contained in this map.
Note that both the set returned by keySet() and the
collection returned by values() support for each loops.
Copyright © 2007 by Stuart C. Shapiro. All rights
reserved.
Last modified: Mon Nov 26 13:47:48 EST 2007
Stuart C. Shapiro
<shapiro@cse.buffalo.edu>