Java Program to Check Whether a Vector Collection Is Empty or Not

You are currently viewing Java Program to Check Whether a Vector Collection Is Empty or Not

Java program to check whether a Vector collection is empty or not

// Java program to check whether a Vector collection 
// is empty or not

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Vector < String > vec1 = new Vector < String > ();
    Vector < String > vec2 = new Vector < String > ();

    vec1.add("CAR");
    vec1.add("BUS");
    vec1.add("BIKE");
    vec1.add("BUS");
    vec1.add("TRUCK");

    if (vec1.isEmpty())
      System.out.println("Vector vec1 is empty collection.");
    else
      System.out.println("Vector vec1 is not empty collection.");

    if (vec2.isEmpty())
      System.out.println("Vector vec2 is empty collection.");
    else
      System.out.println("Vector vec2 is not empty collection.");
  }
}

Output

Vector vec1 is not empty collection.
Vector vec2 is empty collection.

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply