public Object remove(Object key)
remove in Map .
From javadoc :
Deletes the display of this key from this card, if present (additional operation). More formally, if this map contains a map from key k to v, so that (key==null ? k==null : key.equals(k)), , that map is deleted. (A map can contain no more than one such display.)
Returns the value to which the map was previously bound, or null if there was no mapping in the map for this key. (A null return may also indicate that the previously associated card is null with the specified key, if the implementation supports null values.) The card will not contain a mapping for the specified key after the call returns.
Options:
key - a key whose display must be removed from the card.
Returns
The previous value associated with the specified key, or null if there was no mapping for the key.
Example:
Map<Integer, String> map=new HashMap<>(); map.put(20, "stackOverflow"); System.out.println(map.remove(20));
This code will print "stackOverflow" ie The previous value associated with the specified key. Hope it helps.
source share