Showing posts with label create hashtable. Show all posts
Showing posts with label create hashtable. Show all posts

Thursday, 11 June 2015

How to create HashTable In Java

import java.util.Hashtable;

public class CreateHashTable {
   
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");
   
    //print hashtable
    System.out.println("Hash Table is ="+ht);
     }   
}

Output:

Hash Table is ={5=php, 4=c, 3=spring, 2=jersey, 1=java}