java.util.HashSet.isEmpty() 方法
描述
isEmpty() 方法用于检查该集合是否不包含任何元素。
声明
以下是 java.util.HashSet.isEmpty() 方法的声明。
public boolean isEmpty()
参数
NA
返回值
如果此集合不包含任何元素,则方法调用返回"true"。
异常
NA
示例
下面的例子展示了 java.util.HashSet.isEmpty() 的用法。
package com.tutorialspoint;
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

