Get Size of Hashtable - Java Collection Framework

Java examples for Collection Framework:Hashtable

Description

Get Size of Hashtable

Demo Code

 
import java.util.Hashtable;
 
public class Main {
 
  public static void main(String[] args) {
    Hashtable ht = new Hashtable();
    System.out.println("Size of Hashtable : " + ht.size());
   /*www . j a v  a  2  s .c  om*/
    //add key value pairs to Hashtable using put method
    ht.put("1","One");
    ht.put("2","Two");
    ht.put("3","Three");
    System.out.println("Size of Hashtable after addition : " + ht.size());
   
    Object obj = ht.remove("2");
    System.out.println("Size of Hashtable after removal : " + ht.size());
  }
}

Result


Related Tutorials