Contents    Page-10    Prev    Next    Page+10    Index   

Iteration over a Map

A Map does not provide an iterator, so to iterate over it, it must be converted to a Collection that has an iterator. There are three possible collections: keys, values, and key-value pairs.

Set<KeyType> keySet()

Collection<ValueType> values()

Set<Map.Entry<KeyType,ValueType>> entrySet()

The latter option, Map.Entry, has methods for accessing the components:

KeyType getKey()
ValueType getValue()
ValueType setValue( ValueType newValue )