VOOZH about

URL: https://www.geeksforgeeks.org/java/abstractmap-remove-method-in-java-with-examples/

⇱ AbstractMap remove() Method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

AbstractMap remove() Method in Java with Examples

Last Updated : 26 Oct, 2018
The AbstractMap.remove() is an inbuilt method of AbstractMap class and is used to remove the mapping of any particular key from the map. It basically removes the values for any particular key in the Map. Syntax:
AbstractMap.remove(Object key)
Parameters: The method takes one parameter key whose mapping is to be removed from the Map. Return Value: The method returns the value that was previously mapped to the specified key if the key exists else the method returns NULL. Below programs illustrates the working of AbstractMap.remove() method: Program 1: When passing an existing key.
Output:
Initial Mappings are: {20=Geeks, 25=Welcomes, 10=Geeks, 30=You, 15=4}
Returned value is: Geeks
New map is: {25=Welcomes, 10=Geeks, 30=You, 15=4}
Program 2: When passing a new key.
Output:
Initial Mappings are: {20=Geeks, 25=Welcomes, 10=Geeks, 30=You, 15=4}
Returned value is: null
New map is: {20=Geeks, 25=Welcomes, 10=Geeks, 30=You, 15=4}
Note: The same operation can be performed with any type of Mappings with variation and combination of different data types.
Comment