Java TreeMap Size Example

This example shows how to get TreeMap size in Java using the size method. The size method returns the number of entries stored in the TreeMap object.

How to get TreeMap size using the size method in Java (TreeMap length)?

The size method of the TreeMap class returns the number of entries stored in the TreeMap object.

The size method returns an int value representing the number of key-value mappings stored in the TreeMap object.

Output

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

We can get the size of the TreeMap using the size method and compare the return value with 0 to check if the TreeMap is empty or not.

Output

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

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

References:
Java 8 TreeMap

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