![]() |
VOOZH | about |
The AbstractMap put() method inserts a mapping into an AbstractMap. This means we can add a specific key and its value, into a particular map. If an existing key is passed, then the previous value gets replaced by the new value. If a new pair is passed, then the pair gets inserted as a whole.
Output:
Initial Mappings are: {1=Java, 2=JavaScript, 3=Python}
Returned value is: Python
New map is: {1=Java, 2=JavaScript, 3=Geeks}
AbstractMap.put(key, value)Let's see some examples of how to use the Java AbstractMap put() method in Java.
How to add a new element in AbstractMap with Java put() function (passing an existing key).
Initial Mappings are: {20=Geeks, 25=Welcomes, 10=Geeks, 30=You, 15=4}
Returned value is: Geeks
New map is: {20=All, 25=Welcomes, 10=Geeks, 30=You, 15=4}
Adding a new element in AbstractMap (passing a new key).
Initial Mappings are: {20=Geeks, 25=Welcomes, 10=Geeks, 30=You, 15=4}
Returned value is: null
New map is: {50=All, 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.
Read More AbstractMap Methods
Whether you are a beginner starting Java programming or an experienced looking to brush up on your Java skills, this tutorial will provide you with a deep understanding of the AbstractMap put function and its uses in Java.
The AbstractMap put() method in Java is a fundamental function for AbstractMap manipulation. With this guide, you can easily add/put new elements to AbstractMap using the AbstractMap put function.