A
is an object that maps keys to values. A map cannot contain duplicate keys: Each key can map to at most one value. The
Map

Map
interface is shown below: public interface Map {
// Basic Operations
Object put(Object key, Object value);
Object get(Object key);
Object remove(Object key);
boolean containsKey(Object key);
boolean containsValue(Object value);
int size(); boolean isEmpty();
// Bulk Operations
void putAll(Map t);
void clear();
// Collection Views
public Set keySet();
public Collection values();
public Set entrySet();
// Interface for entrySet elements
public interface Entry {
Object getKey();
Object getValue();
Object setValue(Object value);
}
}
The JDK contains two new general-purpose
, which stores its entries in a hash table, is the best-performing implementation.
, which stores its entries in a red-black tree, guarantees the order of iteration. Also,
has been retrofitted to implement
Map
implementations. HashMap

TreeMap

Hashtable

Map
. For more information on implementations, see the Implementations lesson.
No comments:
Post a Comment