Get Vector Size or Length in Java Example

This example shows how to get vector size in Java. This example also shows how to get the vector size or length using the size method.

How to get Vector size or Vector length in Java?

The size method of the Vector class returns the number of elements contained in this vector object.

It returns an int number that is equal to the number of elements currently stored in this vector object. It returns 0 if the vector does not have any elements.

Output

We can also use the size method to check if the Vector object is empty or not. To do that, we need to compare the return value of the size method with 0. If it is equal to 0 then the vector is empty, otherwise, it is not.

Output

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

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

References:
Java 8 Vector 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