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.
相关用法
- Java ConcurrentSkipListSet first()用法及代码示例
- Java ConcurrentSkipListSet add()用法及代码示例
- Java ConcurrentSkipListSet last()用法及代码示例
- Java ConcurrentSkipListSet remove()用法及代码示例
- Java ConcurrentSkipListSet higher()用法及代码示例
- Java ConcurrentSkipListSet size()用法及代码示例
- Java ConcurrentSkipListSet headSet()用法及代码示例
- Java ConcurrentSkipListSet clear()用法及代码示例
- Java ConcurrentSkipListSet descendingSet()用法及代码示例
- Java ConcurrentSkipListSet equals()用法及代码示例
- Java ConcurrentSkipListSet pollFirst()用法及代码示例
- Java ConcurrentSkipListSet removeAll()用法及代码示例
- Java ConcurrentSkipListSet subSet()用法及代码示例
- Java ConcurrentSkipListSet pollLast()用法及代码示例
- Java ConcurrentSkipListSet floor()用法及代码示例
注:本文由纯净天空筛选整理自rupesh_rao大神的英文原创作品 ConcurrentSkipListSet contains() method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。