![]() |
VOOZH | about |
The put() method of the Java HashMap class is used to add or update the key-value pairs in the map. If the key already exists in the map, the previous value associated with the key is replaced by the new value and If the key does not exist, the new key-value pair is added to the map.
public V put(K key, V value)
Parameters:
Return Types:
Example: The below Java program demonstrates the use of put() method to insert key-value pairs into the HashMap.
HashMap: {Java=1, language=3, programming=2}