Java Utility Library

Java Vector - isEmpty() Method



The java.util.Vector.isEmpty() method is used to check whether the vector is empty or not. It returns true if the size of the vector is zero, else returns false.

Syntax

public boolean isEmpty()

Parameters

No parameter is required.

Return Value

true if the vector is empty, else returns false.

Exception

NA

Example:

In the example below, the java.util.Vector.isEmpty() method is used to check whether the vector is empty or not.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a vector
    Vector<Integer> MyVector = new Vector<Integer>();

    //checking vector
    System.out.println("Is MyVector empty?: " + MyVector.isEmpty());

    //populating vector
    MyVector.addElement(10);
    MyVector.addElement(20);
    MyVector.addElement(30);

    //checking vector
    System.out.println("Is MyVector empty?: " + MyVector.isEmpty());
  }
}

The output of the above code will be:

Is MyVector empty?: true
Is MyVector empty?: false

❮ Java.util - Vector