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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。