Home » Java programming language

Java Vector isEmpty() method with Example

Vector Class isEmpty() method: Here, we are going to learn about the isEmpty() method of Vector Class with its syntax and example.
Submitted by Preeti Jain, on March 17, 2020

Vector Class isEmpty() method

  • isEmpty() method is available in java.util package.
  • isEmpty() method is used to check whether this Vector is "empty" or "not empty".
  • isEmpty() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • isEmpty() method does not throw an exception at the time checking the empty status of this Vector.


    public boolean isEmpty();


  • It does not accept any parameter.

Return value:

The return type of the method is boolean, it returns true when this Vector is empty otherwise it returns false.


// Java program to demonstrate the example 
// of boolean isEmpty() method of Vector 

import java.util.*;

public class IsEmptyAtOfVector {
    public static void main(String[] args) {
        // Instantiates a Vector object  with
        // initial capacity of "10"
        Vector < String > v = new Vector < String > (10);

        // By using add() method is to add the
        // elements in this v

        // Display Vector
        System.out.println("v: " + v);

        // By using isEmpty() method is to
        // check the empty status of this Vector
        boolean status = v.isEmpty();

        // Display status
        System.out.println("v.isEmpty(): " + status);


v: [C, C++, JAVA]
v.isEmpty(): false

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.