There are several ways to iterate over the map content using the following Map methods, for example:
- Set<K> keySet(): It returns the keys associated with the values stored in the map. One can iterate over this set and retrieve from the map the value for each key (see the preceding section for who to iterate over a set).
- Collection<V> values(): It returns the values stored in the map. One can iterate over this collection.
- Set<Map.Entry<K,V>> entrySet(): It returns the entries (key-value pairs) stored in the map. One can iterate over this set and get the key and the value from each entry.
- forEach (BiConsumer<? super K,? super V> action): It iterates over key-value pairs stored in the map and provides them as an input into ...