當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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<Integer> Lset =  
                   new ConcurrentSkipListSet<Integer>(); 
  
        // 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<Integer> Lset =  
                       new ConcurrentSkipListSet<Integer>(); 
  
        // 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://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#add(E)



相關用法


注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 ConcurrentSkipListSet isEmpty() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。