Java Hashtable - isEmpty() Method
The java.util.Hashtable.isEmpty() method is used to check whether the hashtable maps no keys to values. It returns true if the hashtable maps no key, else returns false.
Syntax
public boolean isEmpty()
Parameters
No parameter is required.
Return Value
Returns true if the hashtable maps no keys to values, else returns false.
Exception
NA
Example:
In the example below, the java.util.Hashtable.isEmpty() method is used to check whether the hashtable is empty or not.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a hashtable Hashtable<Integer, String> Htable = new Hashtable<Integer, String>(); //checking for empty System.out.println("Is Htable empty?: "+ Htable.isEmpty()); //populating hashtable Htable.put(101, "John"); Htable.put(102, "Marry"); Htable.put(103, "Kim"); Htable.put(104, "Jo"); //checking for empty System.out.println("Is Htable empty?: "+ Htable.isEmpty()); } }
The output of the above code will be:
Is Htable empty?: true Is Htable empty?: false
❮ Java.util - Hashtable