How to Get Size of LinkedHashSet in Java Example

This example shows how to get the size of the LinkedHashSet object in Java (LinkedHashSet length). This example also shows how to use the LinkedHashSet size method.

How to get the size of the LinkedHashSet using the size method?

The size method of the LinkedHashSet class returns the number of elements currently stored in the LinkedHashSet object.

The size method returns an int value representing the number of elements of the linked hash set object. It returns 0 if the set object is empty or does not contain any elements.


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

We can check if LinkedHashSet is empty using the size method. In order to do that, we need to compare the output of the size method with 0 as given below. If the return value of the size method is 0 then the linked hash set is empty, otherwise not.


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

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

Java 8 LinkedHashSet

About the author



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 *