There are two more methods that we need to cover before wrapping up this chapter. They are the insert(Object key, Object value)
and update(Object key, Object value)
methods.
The insert(Object key, Object value)
method will attempt to insert a new value into a BackingMap. This method will never update an object with its key that already exists in the BackingMap. If the key already exists in the BackingMap, then a DuplicateKeyException
is thrown. A call to the insert(Object key, Object value)
method is telling a BackingMap that we expect to put a new key/value pair in, or do nothing if that key already exists. Insert means insert a new key/value pair, not update a key/value pair.
The update(Object key, Object value)
method requires that a key already exists in the map to be considered a success. This method updates the object with the specified key, meaning that the key must already exist in the map. If the key is not in the BackingMap, a KeyNotFoundException
is thrown. Update means...