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

RahimV

RahimV

My name is RahimV and I have over 16 years of experience in designing and developing Java applications. Over the years I have worked with many fortune 500 companies as an eCommerce Architect. My goal is to provide high quality but simple to understand Java tutorials and examples for free. If you like my website, follow me on Facebook and Twitter.

Add Comment

Your email address will not be published. Required fields are marked *

Online Shopping