isEmpty()%uA0方法是用来检查,此集合是否不包含任何元素(是否为空)。
声明
以下是java.util.HashSet.isEmpty()方法的声明。
public boolean isEmpty()
参数
-
NA
返回值
该方法调用返回true,如果此set不包含任何元素。
异常
-
NA
例子
下面的例子显示java.util.HashSet.isEmpty()方法的使用
package com.yiibai 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