java.util.Vector.isEmpty()方法实例
isEmpty() 方法用于测试此向量是否不包含组件(是一个空向量)。
声明
以下是java.util.Vector.isEmpty()方法的声明
public boolean isEmpty()
参数
-
NA
返回值
返回值是true当且仅当此向量没有组件,也就是说,它的大小是零。否则返回false。
异常
-
NA
例子
下面的例子显示java.util.Vector.isEmpty()方法的使用。
package com.yiibai; import java.util.Vector; public class VectorDemo { public static void main(String[] args) { // create an empty Vector vec with an initial capacity of 4 Vectorvec = new Vector (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