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

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

Java中的 ConcurrentSkipListSet contains() 方法

Java .util.concurrent.ConcurrentSkipListSetcontains()方法是Java中的一个内置函数,如果指定元素存在于此集合中,则返回 true 布尔值,否则返回 false。

句法:

ConcurrentSkipListSet.contains(Object o)

参数:该函数接受单个参数即检查该参数是否存在。

返回值:函数返回一个布尔值。如果此集合中存在指定的元素,则返回 True,否则返回 False。

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

方案一:

// Java Program Demonstrate contains()
// method of ConcurrentSkipListSet
  
import java.util.concurrent.*;
  
class ConcurrentSkipListSetContainsExample1 {
    public static void main(String[] args)
    {
  
        // Initializing the set
        ConcurrentSkipListSet
            set = new ConcurrentSkipListSet();
  
        // 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.

方案二:

// Java Program Demonstrate contains()
// method of ConcurrentSkipListSet */
  
import java.util.concurrent.*;
  
class ConcurrentSkipListSetContainsExample2 {
    public static void main(String[] args)
    {
  
        // Initializing the set
        ConcurrentSkipListSet
            set = new ConcurrentSkipListSet();
  
        // 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: Java/util/concurrent/ConcurrentSkipListSet.html#contains-java.lang.Object-