![]() |
VOOZH | about |
The Hashtable.put() method is a part of java.util package. This method is used to insert a mapping into a table. This means we can insert a specific key and the value it maps to into a particular table. 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.
Below is the syntax of put() method.
Hash_Table.put(key, value)
Parameters:
This method takes two parameters, both of the Object type of the Hashtable.
Return Value: If an existing key is passed, the previous value gets returned. If a new pair is passed, then null is returned.
Example 1: In this example, we are going to use the put() method when an existing key is passed.
Example 2: In this example, let's use the put() method when a new key is passed and we will see what it prints.
Important Points: