Java中的ConcurrentSkipListSet isEmpty()方法
java.util.concurrent.ConcurrentSkipListSet.isEmpty()方法是Java中的内置函数,用于检查此集合是否为空。
语法:
ConcurrentSkipListSet.isEmpty()
参数: 该函数不接受任何参数。
返回值: 该函数返回布尔值。如果ConcurrentSkipListSet为空,则返回true,否则返回false。
下面的程序演示了ConcurrentSkipListSet.IsEmpty ()方法:
程序1: 在此程序中,ConcurrentSkipListSet非空。
// Java程序演示isEmpty()方法以展示ConcurrentSkipListSet()
import java.util.concurrent.*;
class ConcurrentSkipListSetIsEmptyExample1 {
public static void main(String[] args)
{
// 创建一个集合对象
ConcurrentSkipListSet<Integer> Lset =
new ConcurrentSkipListSet<Integer>();
// 向此集合中添加元素
for (int i = 10; i <= 50; i += 10)
Lset.add(i);
// 检查此集合是否为空
if (Lset.isEmpty())
System.out.println("集合为空。");
else
System.out.println("集合非空。");
}
}
集合非空。
程序2: 在此程序中,ConcurrentSkipListSet为空。
// Java程序演示isEmpty()方法以展示ConcurrentSkipListSet()
import java.util.concurrent.*;
class ConcurrentSkipListSetIsEmptyExample2 {
public static void main(String[] args)
{
// 创建一个集合对象
ConcurrentSkipListSet<Integer> Lset =
new ConcurrentSkipListSet<Integer>();
// 检查此集合是否为空
if (Lset.isEmpty())
System.out.println("集合为空。");
else
System.out.println("集合非空。");
}
}
集合为空。
参考资料: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#add(E)
极客教程