How to get value of key in HashTable

import java.util.Hashtable;

public class HashTableGetValueOfkey {

public static void main(String[] args) {

Hashtable<Integer,String> ht = new Hashtable<Integer,String>();

/*
* Maps the specified key to the specified
* value in this hashtable
*/
ht.put(1, “java”);
ht.put(2, “jersey”);
ht.put(3, “spring”);
ht.put(4, “c”);
ht.put(5, “php”);

System.out.println(” key = 1 and value =”+ht.get(1));

System.out.println(” key = 2 and value =”+ht.get(2));

System.out.println(” key = 9 and value =”+ht.get(9));

}

}

Output:

key = 1 and value =java

key = 2 and value =jersey

key = 9 and value =null

Leave a Reply

Your email address will not be published. Required fields are marked *

42 − = 38