HashMaps
HashMaps?
- A
HashMapsare a type ofmap. Mapsare collections ofkey-value pairsthat aresearchable.Mapsare unordered.Mapsstore and retrieve data using the keys to identify entries.Keysmust be unique. They cannot be changed(=immutable) e.g> <k:A, v:3> <k:A, v:4> CANNOT exist in the same mapValuesare not unique, and therefore, they can be changed(=mutable) e.g> <k:A, v:3> <k:B, v:3> CAN exist in the same mapMapsalso sometimes calleddictionaries.- A real life example of
KVpairsis phone numbers and names.
Phone Number = KEY
Name = VALUE
Map ADT
Methods:
- V put(<K, V>)
- V get(K)
- V remove(K)
- int size()
SIZErefers to the number of entries, nCAPACITYrefers to the length of the backing array, N
Leave a comment