The HashTable.get()
method is present in the HashTable
class inside the java.util
package.
The HashTable.get()
method is used to retrieve the value of the passed key from the HashTable
.
The HashTable.get()
method takes one parameter:
key
: The key whose corresponding value needs to be retrieved from the HashTable
.The HashTable.get()
method returns the value elements associated with the key.
Let’s take a look at the below code snippet.
import java.util.*;class Main{public static void main(String[] args){Hashtable<Integer, String> h1 = new Hashtable<Integer, String>();h1.put(1, "Let's");h1.put(5, "see");h1.put(2, "Hashtable.contains()");h1.put(27, "method");h1.put(9, "in java.");System.out.println("The value with key=9 is: " + h1.get(9));System.out.println("The value with key=5 is: " + h1.get(5));System.out.println("The value with key=27 is: " + h1.get(27));}}
Main
class.main
function.HashTable
consisting of Integer
type keys and String
type values.HashTable
by using the Hashtable.put()
method.HashTable.get()
method.In this way, we can use HashTable.get()
method to retrieve the value of the passed key from the HashTable
.