share

Thursday, 11 June 2015

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

No comments:

Post a Comment