Java Collection Tutorial - Java Hashtable.isEmpty()


Hashtable.isEmpty() has the following syntax.

public boolean isEmpty()


In the following code shows how to use Hashtable.isEmpty() method.

/*from  ww w  . j a va  2s. c  o m*/

import java.util.Hashtable;

public class Main {
   public static void main(String args[]) {
      // create hash table 
      Hashtable<Integer,String> htable1 = new Hashtable<Integer,String>();      
      // put values in table
      htable1.put(1, "A");
      htable1.put(2, "B");
      htable1.put(3, "C");
      htable1.put(4, "from");
      // check if table is empty
      System.out.println("Is hash table empty :"+htable1.isEmpty()); 

The code above generates the following result.