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


Java ConcurrentSkipListSet contains()用法及代碼示例


java.util.concurrent.ConcurrentSkipListSet的contains()方法是Java中的內置函數,如果指定的元素存在於此集合中,則該函數返回true布爾值,否則返回false。

用法:

ConcurrentSkipListSet.contains(Object o)

參數:該函數接受單個參數o,即檢查該參數是否存在。


返回值:該函數返回一個布爾值。如果指定的元素存在於此集中,則返回True;否則返回False。

以下示例程序旨在說明ConcurrentSkipListSet.contains()方法:

示例1:

// Java Program Demonstrate contains() 
// method of ConcurrentSkipListSet 
  
import java.util.concurrent.*; 
  
class ConcurrentSkipListSetContainsExample1 { 
    public static void main(String[] args) 
    { 
  
        // Initializing the set 
        ConcurrentSkipListSet<Integer> 
            set = new ConcurrentSkipListSet<Integer>(); 
  
        // Adding elements to this set 
        for (int i = 10; i <= 15; i++) 
            set.add(i); 
  
        // Checks if 9 is present in the set 
        if (set.contains(9)) 
            System.out.println("9 is present in the set."); 
        else
            System.out.println("9 is not present in the set."); 
    } 
}
輸出:
9 is not present in the set.

示例2:

// Java Program Demonstrate contains() 
// method of ConcurrentSkipListSet */ 
  
import java.util.concurrent.*; 
  
class ConcurrentSkipListSetContainsExample2 { 
    public static void main(String[] args) 
    { 
  
        // Initializing the set 
        ConcurrentSkipListSet<String> 
            set = new ConcurrentSkipListSet<String>(); 
  
        // Adding elements to this set 
        set.add("Gfg"); 
        set.add("is"); 
        set.add("fun"); 
  
        // Checks if Gfg is present in the set 
        if (set.contains("Gfg")) 
            System.out.println("Gfg is present in the set."); 
        else
            System.out.println("Gfg is not present in the set."); 
    } 
}
輸出:
Gfg is present in the set.

參考: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#contains-java.lang.Object-



相關用法


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