HashMap Hashtable

Definition

A Map is a list, in which every entry consist of a key object (key) and the depending value object (value). Every key can be mapped to one value, double keys are not possible.

If you add a new Map.Entry (key-value-pair) and the key already exists in the list, then the existing value object will be replaced by the new. The sorting of the list entries is arbitrary and could change.

The difference between HashMap and Hashtable is, that a HashMap is not synchronized (faster) and permits null-key / null-value. In most cases a HashMap will be used.

Example

Map<String,User> map = new HashMap<String,User>(); map.put("U-12345", new User()); map.put("U-12346", new User()); for (Map.Entry<String,User> entry : map.entrySet()) System.out.println(entry.getKey() +"="+ entry.getValue());

Author: Johannes HammoudComments Date: 09.02.2006

Language German

Java JSF XHTML WML JavaScript GlassFish MySQL NetBeans

Imprint

Visits
582379
Today
35