当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。