![]() |
VOOZH | about |
The Hashtable.isEmpty() method is a built-in method of the java.util.Hashtable class. This method is used to check if the table is empty or not. The method returns true, if no key-value pair or mapping is present in the table, else it returns false.
hash_table.isEmpty();
This method is used to check the state of the table before performing the operations like iteration, retrieval, or updates.
Example 1: In this example, we create a Hashtable with String keys and Integer values. Then we will insert multiple key-value pairs. After this, we will check if the table is empty using the isEmpty() method.
The table is: {You=30, Welcomes=25, 4=15, Geeks=20}
Is the table empty? false
Example 2: In this example, we are going to create an empty Hashtable without adding any elements. In this case, the isEmpty() method will return true because the table has no key-value mappings.
The table is: {}
Is the table empty? true
Note: The same operation can be performed with any type of variation and combination of different data types.