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());

Johannes Hammoud HashMap Hashtable 09.02.2006

I Coding : Community about Java programing

Language German+-

Java JSF JavaScript HTML CSS NetBeans GlassFish MySQL

Imprint

Visits
5744578
Today
147