java.util.Vector.isEmpty() 方法
描述
isEmpty() 方法用于测试该向量是否没有分量。
声明
以下是 java.util.Vector.isEmpty() 方法的声明
public boolean isEmpty()
参数
NA
返回值
当且仅当这个向量没有分量,即它的大小为零时,返回值为真。否则返回假。
异常
NA
示例
下面的例子展示了 java.util.Vector.isEmpty() 方法的使用。
package com.tutorialspoint;
import java.util.Vector;
public class VectorDemo {
public static void main(String[] args) {
// create an empty Vector vec with an initial capacity of 4
Vector<Integer> vec = new Vector<Integer>(4);
// let us test the vector
System.out.println("The vector does not have any element");
System.out.println("The vector is empty: "+vec.isEmpty());
// use add() method to add elements in the vector
vec.add(4);
vec.add(3);
vec.add(2);
vec.add(1);
// let us test the vector again
System.out.println("The vector has elements");
System.out.println("The vector is empty: "+vec.isEmpty());
}
}
让我们编译并运行上面的程序,这将产生以下结果.
The vector does not have any element The vector is empty: true The vector has elements The vector is empty: false

