Vector class isEmpty()method example
Tests if this vector has no components.
Vector class isEmpty()method example. This example shows you how to use isEmpty()method.This method Tests if this vector has no components.
Here is the code:-
/*
* @Program that Tests if this vector has no components.
* IsEmpty.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class IsEmpty {
public static void main(String[] args) {
//Creating vector
Vector v = new Vector();
//Adding element to the vector
v.add("Rose");
v.add("India");
v.add("Rohini");
v.add("Girish");
//Creating Enumeration Interface
Enumeration e = v.elements();
System.out.print("Vector is : ");
while (e.hasMoreElements()) {
System.out.print(e.nextElement() + "\t");
}
//Tests if vector v has no components.
boolean b = v.isEmpty();
System.out.println("");
System.out.println("Vector is Empty : " + b);
//Creating another vector
Vector v1 = new Vector();
System.out.print("Vector is : ");
//Tests if vector v1 has no components.
boolean b1 = v1.isEmpty();
System.out.println("");
System.out.println("Vector is Empty : " + b1);
}
} |
Output of the program:-
Vector is : Rose India Rohini Girish
Vector is Empty : false
Vector is :
Vector is Empty : true |
|