Java Vector.isEmpty() Method

 Posted On  | Yashwant Chavan 

In this tutorial, you will learn about Java Vector.isEmpty() Method. This method checks if this vector has no elements (Vector is empty or not?).

syntax

Tests if this vector has no elements.

boolean java.util.Vector.isEmpty()

Return

returns true if and only if this vector has no elements, false otherwise.

Java example to check if Vector has no elements

  • Create Vector instance using new Vector().
  • Add some elements in the Vector.
  • In first scenario we have some elements in Vector, so it returns false.
  • In second scenario, It returns true value because we have removed all the elements from Vector.
package com.technicalkeeda.app;

import java.util.Vector;

public class VectorIsEmpty {
    public static void main(String[] args) {

        Vector < String > colors = new Vector < String > ();
        colors.add("Red");
        colors.add("Green");
        colors.add("Blue");
        colors.add("Pink");

        System.out.println("Vector isEmpty() before:- ? " + colors.isEmpty());
        colors.removeAllElements();
        System.out.println("Vector isEmpty() after:- ? " + colors.isEmpty());

    }
}

Output

Vector isEmpty() before:- ? false
Vector isEmpty() after:- ? true


© technicalkeeda.com 2017

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0383 seconds.