Skip to content

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

Leave a Reply

Your email address will not be published.