Vector isEmpty() Method in Java Last Updated : 24 May, 2023 Comments Improve Suggest changes Like Article Like 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). Comment More infoAdvertise with us Next Article Vector isEmpty() Method in Java K kundankumarjha Follow Improve Article Tags : Java Java-Collections Java - util package Java-Functions Java-Vector +1 More Practice Tags : JavaJava-Collections Similar Reads Java Vector clone() Method In Java, the clone() method of the Vector class is used to return a shallow copy of the vector. It just creates a copy of the vector. The copy will have a reference to a clone of the internal data array but not a reference to the original internal data array.Example 1: In this example, we use the cl 3 min read Java Vector contains() Method The contains() method in Java is used to check whether a specific element is present in the Vector or not.Example 1: In this example, we will check whether a particular string is present in the vector or not.Java// Java program to demonstrate the use // of the contains() method with Strings import j 3 min read Java Vector containsAll() Method In Java, the containsAll() method is used to check if the Vector contains all the elements of a specified Collection or not.Example 1: Below program demonstrating the use of containsAll() method with Strings.Java// Java Program to demonstrate the use of // containsAll() with Strings import java.util 2 min read Java Vector copyInto() Method In Java, the copyInto() method is used to copy all the components from one vector to another array, having enough space to hold all of the components of the vector. It is to be noted that the index of the elements remains unchanged. The elements present in the array are replaced by the elements of t 3 min read Java Vector elementAt() Method In Java, the elementAt() method is used to fetch or retrieve an element at a specific index from a Vector. It allows to access elements in the vector by providing the index, which is zero-based.Example 1: Here, we use the elementAt() method to retrieve an element at a specified index with an Integer 2 min read Java Vector elements() Method In Java, the elements() method is used to return an enumeration of the elements in the Vector. This method allows you to iterate over the elements of a Vector using an Enumeration, which provides methods for checking if there are more elements and retrieving the next element.Example 1: Below is the 2 min read Vector ensureCapacity() method in Java with Example The ensureCapacity() method of Java.util.Vector class increases the capacity of this Vector instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument. Syntax: public void ensureCapacity(int minCapacity) Parameters: This method takes 2 min read Vector equals() Method in Java The java.util.vector.equals(Object obj) method of Vector class in Java is used verify the equality of an Object with a vector and compare them. The list returns true only if both Vector contains same elements with same order. Syntax: first_vector.equals(second_vector) Parameters: This method accepts 2 min read Vector firstElement() Method in Java The java.util.vector.firstElement() method in Java is used to retrieve or fetch the first element of the Vector. It returns the element present at the 0th index of the vector Syntax: Vector.firstElement() Parameters: The method does not take any parameter. Return Value: The method returns the first 2 min read Vector forEach() method in Java The forEach() method of Vector is used to perform a given action for every element of the Iterable of Vector until all elements have been Processed by the method or an exception occurs. The operations are performed in the order of iteration if the order is specified by the method. Exceptions thrown 3 min read Like