Overview

Although our map implementations will include essentially all the functionality of Java’s Map interface, you will only need to implement a few of its methods—all the others will have default implementations that use the methods you implement.

Signature Description
V get​(Object key) Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
V put​(K key, V value) Associates the specified value with the specified key in this map. Returns the previous value associated with key, or null if there was no mapping for key.
V remove​(Object key) Removes and returns the mapping for a key from this map if it is present or returns null otherwise.
void clear() Removes all of the mappings from this map. The map will be empty after this call returns.
boolean containsKey​(Object key) Returns true if this map contains a mapping for the specified key.
int size() Returns the number of key-value mappings in this map.
Iterator<Entry<K, V>> iterator() Returns an iterator that, when used, will yield all key-value mappings contained within this map.

Note

The get, remove, and containsKey methods accept any Object parameters, rather than restricting the key type to K. This should not cause any issues in your map implementations.

Tips

The above does not cover the full description of the interfaces. You can find more details on the expected parameters, functionality, and return value if you open up Java’s documentation of each interface.

For ArrayMap and ChainedHashMap, in order to see the complete documentation of the AbstractIterableMap interface in Java, you may

  • hold Ctrl if you are on windows
  • hold Cmd if you are on mac

and click on the AbstractIterableMap text. The documentation should open up after the click.

Similarly, in the class header for ArrayMapIterator or ChainedHashMapIterator,

  • hold Ctrl if you are on windows
  • hold Cmd if you are on mac

and click on the Iterator to see the documentation for the Iterator interface.

Alternatively, you may choose to right click on the text of the interface name, hover on “Go To”, and then select “Declaration or Usages”.

open up a documentation

You can do this with class names and method names in IntelliJ! This is especially useful if you need the documentation for interfaces or if you want to know what methods are available to you for any Object.