Online Java Compiler By
JavaTpoint.com
import java.util.*; public class VectorIsEmptyExample1 { public static void main(String arg[]) { //Create an empty vector Vector < String > vec = new Vector < String > (); //Add elements in the vector vec.add("Java"); vec.add("Ruby"); vec.add("Android"); vec.add("Python"); //Displaying the Vector System.out.println("Vector: " + vec); //Verifying if the Vector is empty or not System.out.println("Is the Vector empty? = " +vec.isEmpty()); //Clear the Vector vec.clear(); //Displaying the Vector Again System.out.println("Vector after clear(): " +vec); //Verifying if the Vector is empty or not System.out.println("Is the Vector empty? = " +vec.isEmpty()); } }
Output