boolean isEmpty()
描述 (Description)
isEmpty()方法用于检查此集合是否不包含任何元素。
声明 (Declaration)
以下是java.util.HashSet.isEmpty()方法的声明。
public boolean isEmpty()
参数 (Parameters)
NA
返回值 (Return Value)
如果此set不包含任何元素,则方法调用返回'true'。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.util.HashSet.isEmpty()的用法
package com.iowiki;
import java.util.*;
public class HashSetDemo {
public static void main(String args[]) {
// create hash set
HashSet <String> newset = new HashSet <String>();
// populate hash set
newset.add("Learning");
newset.add("Easy");
newset.add("Simply");
// check if the has set is empty
boolean isempty = newset.isEmpty();
System.out.println("Is the hash set empty: "+ isempty);
}
}
让我们编译并运行上面的程序,这将产生以下结果。
Is the hash set empty: false