The Wayback Machine - https://web.archive.org/web/20240618020132/https://www.geeksforgeeks.org/vector-isempty-method-in-java/
Open In App

Vector isEmpty() Method in Java

Last Updated : 24 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The Java.util.Vector.isEmpty() method in Java is used to check and verify if a Vector is empty or not. It returns True if the Vector is empty else it returns False. 

Syntax:

Vector.isEmpty()

Parameters: This method does not take any parameter. 

Return Value: This function returns True if the Vectoris empty else it returns False. 

Below programs illustrate the Java.util.Vector.isEmpty() method: 

Program 1: 

Java




// Java code to illustrate isEmpty()
import java.util.*;
 
public class VectorDemo {
    public static void main(String args[])
    {
        // Creating an empty Vector
        Vector<String> vec_tor = new Vector<String>();
 
        // Use add() method to add elements into the Vector
        vec_tor.add("Welcome");
        vec_tor.add("To");
        vec_tor.add("Geeks");
        vec_tor.add("4");
        vec_tor.add("Geeks");
 
        // Displaying the Vector
        System.out.println("Vector:  " + vec_tor);
 
        // Verifying if the Vector is empty or not
        System.out.println("Is the Vector empty? "
                           + vec_tor.isEmpty());
 
        // Clearing the Vector
        vec_tor.clear();
 
        // Displaying the Vector
        System.out.println("Vector after clear(): "
                           + vec_tor);
 
        // Verifying if the Vector is empty or not
        System.out.println("Is the Vector empty? "
                           + vec_tor.isEmpty());
    }
}


Output:

Vector:  [Welcome, To, Geeks, 4, Geeks]
Is the Vector empty? false
Vector after clear(): []
Is the Vector empty? true

Program 2: 

Java




// Java code to illustrate isEmpty()
import java.util.*;
 
public class VectorDemo {
    public static void main(String args[])
    {
        // Creating an empty Vector
        Vector<Integer> vec_tor = new Vector<Integer>();
 
        // Displaying the Vector
        System.out.println("Vector:  " + vec_tor);
 
        // Verifying if the Vector is empty or not
        System.out.println("Is the Vector empty? "
                           + vec_tor.isEmpty());
    }
}


Output:

Vector:  []
Is the Vector empty? true

Time complexity: O(1).
Auxiliary Space: O(1).



Previous Article
Next Article

Similar Reads

Java String isEmpty() method with example
Java.lang.String.isEmpty() String method checks whether a String is empty or not. This method returns true if the given string is empty, else it returns false. The isEmpty() method of the String class is included in Java string since JDK 1.6. In other words, you can say that this method returns true if the length of the string is 0. Syntax of Java
3 min read
HashSet isEmpty() Method in Java
The Java.util.HashSet.isEmpty() method is used to check if a HashSet is empty or not. It returns True if the HashSet is empty otherwise it returns False. Syntax: Hash_Set.isEmpty() Parameters: This method does not take any parameter Return Value: The function returns True if the set is empty else returns False. Below program illustrate the Java.uti
1 min read
TreeSet isEmpty() Method in Java
The Java.util.TreeSet.isEmpty() method is used to check and verify if a TreeSet is empty or not. It returns True if the TreeSet is empty else it returns False. Syntax: Tree_Set.isEmpty() Parameters: The method does not take any parameter Return Value: The function returns True if the set is empty else it returns False. Below program illustrate the
1 min read
HashMap isEmpty() Method in Java
The java.util.HashMap.isEmpty() method of HashMap class is used to check for the emptiness of the map. The method returns True if no key-value pair or mapping is present in the map else False. Syntax: Hash_Map.isEmpty() Parameters: The method does not take any parameters. Return Value: The method returns boolean true if the map is empty or does not
2 min read
Hashtable isEmpty() Method in Java
The java.util.Hashtable.isEmpty() method of Hashtable class is used to check for the emptiness of the table. The method returns True if no key-value pair or mapping is present in the table else False. Syntax: Hash_Table.isEmpty() Parameters: The method does not take any parameters. Return Value: The method returns boolean true if the table is empty
2 min read
ArrayDeque isEmpty() Method in Java
The Java.util.ArrayDeque.isEmpty() method in Java is used to check and verify if an ArrayDeque is empty or not. It returns True if the Deque is empty else it returns False. Syntax: Array_Deque.isEmpty() Parameters: The method does not take any parameter. Return Value: The function returns True if the deque is empty else it returns False. Below prog
2 min read
BitSet isEmpty() method in Java
BitSet is a class defined in the java.util package. It creates an array of bits represented by boolean values. Prerequisite : Java BitSet | Set 1 Bitset.isEmpty() This method is used to check if there are any bits that are set to true, in the specified BitSet. This method returns true if this BitSet contains no bits that are set to true. Syntax: pu
2 min read
WeakHashMap isEmpty() Method in Java with Examples
The java.util.WeakHashMap.isEmpty() method of HashMap class is used to check for the emptiness of the map. The method returns True if no key-value pair or mapping is present in the map else False. Syntax: Weak_Hash_Map.isEmpty() Parameters: The method does not take any parameters. Return Value: The method returns boolean true if the map is empty or
2 min read
LinkedTransferQueue isEmpty() method in Java
The isEmpty() method of java.util.concurrent.LinkedTransferQueue is an in-built function in Java which checks if this queue is empty or not. Syntax: LinkedTransferQueue.isEmpty() Return Value: The function returns a boolean value. It returns true if the LinkedTransferQueue is empty and returns false otherwise. Below programs illustrate the LinkedTr
1 min read
ConcurrentHashMap isEmpty() Method in Java
The isEmpty() method in Java's ConcurrentHashMap class is used to check whether the map is empty or not. It has the following signature: boolean isEmpty() The isEmpty() method works in a concurrent environment, which means that it can be called from multiple threads without causing any data race or synchronization issues. When an isEmpty() operatio
2 min read