Map Interface
#
Basics- maps Key to Value --
<K, V>
- no duplicated Key allowed, or it will overwrite previous value with the same Key, aka. a key can only map to at most one value
- deplicated Values are allowed
#
Put- Returns previous value in the Key associated:
#
Remove- HashMap remove can uses key as a parameter:
#
Pitfall - ConcurrentModificationException#
Iterate Through Values- use for loop โ use
values()
to iterate through values in a HashMap:
- use
Map.Entry<K, V> entry: map.entrySet()
to iterate through both values and keys: