Skip to content

Java Hashtable Size (Hashtable length) Example

This example shows how to get the Hashtable size (Hashtable length) using the size method. The Hashtable size is the number of entries contained in the hash table object.

How to get the Hashtable size in Java?

The Hashtable size method returns the number of entries or key-value mappings stored in the hash table object.

It returns the number of keys in the hash table object. It returns zero (0) if the hash table is empty.

Output

How to check if the Hashtable is empty using the size method?

The Hashtable size method returns 0 if the hashtable is empty. We can compare the return value of the size method with zero (0) to check if the hash table is empty or not as given below.

Output

This example is a part of the Hashtable in Java Tutorial with Examples.

Please let me know your views in the comments section below.

References:
Java 8 Hashtable Documentation

About the author

Leave a Reply

Your email address will not be published.