Java Vector isEmpty() Example

The isEmpty() method of java.util.Vector class will tests if this vector has any elements or not.

Signature

public boolean isEmpty() 

This method checks if the vector has any elements in it or not, returns true if and only if the vector has no components,else it will return false.

Example

The following example shows the usage of java.util.Vector.isEmpty() method.

import java.util.Vector;

public class IsEmptyMethodVectorExample 
{
    public static void main(String args[])
    {
     // create an empty Vector
        Vector vector1 = new Vector();
        
        // use add() method to add elements to the Vector
        vector1.add("Element1");
        vector1.add("Element2");
        vector1.add("Element3");
        
        //Check if vector1 is empty or not 
        System.out.println("Is \"vector1\" empty : "+vector1.isEmpty());
    }
}

Output

Is "vector1" empty : false

Leave a Reply

Your email address will not be published. Required fields are marked *