Saturday, 12 March 2011

The Map Interface in java

A Map(in the API reference documentation)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 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 Map implementations. HashMap(in the API reference documentation), which stores its entries in a hash table, is the best-performing implementation. TreeMap(in the API reference documentation), which stores its entries in a red-black tree, guarantees the order of iteration. Also, Hashtable(in the API reference documentation)has been retrofitted to implement Map. For more information on implementations, see the Implementations lesson.


 

No comments:

Post a Comment