Java ConcurrentSkipListSet contains()方法
java.util.concurrent.ConcurrentSkipListSet的 contains( )方法是Java中的一个内置函数,如果指定的元素存在于这个集合中,则返回一个真布尔值,否则返回假。
语法
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-