Skip to content

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

Leave a Reply

Your email address will not be published.