📌  相关文章
📜  Java中的 ConcurrentSkipListSet isEmpty() 方法

📅  最后修改于: 2022-05-13 01:55:41.106000             🧑  作者: Mango

Java中的 ConcurrentSkipListSet isEmpty() 方法

Java .util.concurrent.ConcurrentSkipListSet.isEmpty() 方法是Java中的一个内置函数,用于检查该集合是否为空。

句法:

ConcurrentSkipListSet.isEmpty()

参数:该函数不接受任何参数。

返回值:函数返回一个布尔值。如果 ConcurrentSkipListSet 为空,则返回 true,否则返回 false。

下面的程序说明了 ConcurrentSkipListSet.IsEmpty() 方法:

程序 1:在这个程序中,ConcurrentSkipListSet 是非空的。

// Java Program to demonstrate isEmpty()
// method of ConcurrentSkipListSet() 
  
import java.util.concurrent.*;
  
class ConcurrentSkipListSetIsEmptyExample1 {
    public static void main(String[] args)
    {
        // Creating a set object
        ConcurrentSkipListSet Lset = 
                   new ConcurrentSkipListSet();
  
        // Adding elements to this set
        for (int i = 10; i <= 50; i += 10)
            Lset.add(i);
  
        // Checks if this set is empty or not
        if (Lset.isEmpty())
            System.out.println("The set is empty.");
        else
            System.out.println("The set is non-empty.");
    }
}
输出:
The set is non-empty.

程序 2:在这个程序中,ConcurrentSkipListSet 是空的。

// Java program to demonstrate isEmpty()
// method of ConcurrentSkipListSet() 
  
import java.util.concurrent.*;
  
class ConcurrentSkipListSetIsEmptyExample2 {
    public static void main(String[] args)
    {
        // Creating a set object
        ConcurrentSkipListSet Lset = 
                       new ConcurrentSkipListSet();
  
        // Checks if this set is empty or not
        if (Lset.isEmpty())
            System.out.println("The set is empty.");
        else
            System.out.println("The set is non-empty.");
    }
}
输出:
The set is empty.

参考: https: Java/util/concurrent/ConcurrentSkipListSet.html#add(E)