Skip to content

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.

Output

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.

Output

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

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

References:
Java 8 LinkedHashSet

About the author

We are on YouTube!

Leave a Reply

Your email address will not be published.