![]() |
VOOZH | about |
The Hashtable.get() method is a built-in method of the java.util.Hashtable class. This method is used to retrieve or fetch the value mapped by a particular key mentioned in the parameter. It returns NULL when the table contains no such mapping for the key. In this article, we will learn about the Hashtable.get() method in Java with its syntax and practical examples.
Hashtable.get(Object key);
We use get() method,
Example 1: In this example, we create a hashtable with integer keys and string values. We insert key-value pairs and retrieve values using the get() method.
Initial Table is: {10=Geeks, 20=Geeks, 30=You, 15=4, 25=Welcomes}
The Value for key 25 is: Welcomes
The Value for key 10 is: Geeks
Example 2: Here, we create a hashtable with string keys and integer values.
Initial table is: {You=30, Welcomes=25, 4=15, Geeks=20}
The Value for key Geeks is: 20
The Value for key You is: 30
Important Points:
Note: The same operation can be performed with any type of variation and combination of different data types.