Sunday 14 June 2015

How to get size of hashtable


import java.util.Hashtable;

public class HashTableKeyCount {
   
    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");
       
        //Returns the number of keys in this hashtable
       
        System.out.println("Hash Table size  ="+ht.size());
       
       
         }   

}

Output:

Hash Table size  =5




No comments:

Post a Comment