java.util.concurrent.ConcurrentLinkedDeque.contains()方法是Java中的內置方法,用於檢查雙端隊列中是否存在作為參數傳遞的指定元素。
用法:
public boolean contains(Object elem)
參數:該方法接受參數elem,該參數檢查指定的元素是否存在於雙端隊列中。
返回值:如果雙端隊列中存在元素,則函數返回True,否則返回False。
以下示例程序旨在說明ConcurrentLinkedDeque.contains()方法:
程序1:
// Java Program to Demonstrate contains()
// method of ConcurrentLinkedDeque
import java.util.concurrent.*;
class GFG {
public static void main(String[] args)
{
// Creating an empty Deque
ConcurrentLinkedDeque<String> cld = new ConcurrentLinkedDeque<String>();
// Add elements into the Deque
cld.add("Welcome");
cld.add("To");
cld.add("Geeks");
cld.add("4");
cld.add("Geeks");
// Displaying the Deque
System.out.println("ConcurrentLinkedDeque: "
+ cld);
// Check if GFG is present using contains()
if (cld.contains("GFG")) {
// Displaying message
System.out.println("GFG is present");
}
else {
// Displaying message
System.out.println("GFG is not present");
}
}
}
輸出:
ConcurrentLinkedDeque: [Welcome, To, Geeks, 4, Geeks] GFG is not present
示例2:
// Java Program to Demonstrate contains()
// method of ConcurrentLinkedDeque
import java.util.concurrent.*;
class GFG {
public static void main(String[] args)
{
// Creating an empty Deque
ConcurrentLinkedDeque<String> cld = new ConcurrentLinkedDeque<String>();
// Add elements into the Deque
cld.add("Welcome");
cld.add("To");
cld.add("Geeks");
cld.add("4");
cld.add("Geeks");
// Displaying the Deque
System.out.println("ConcurrentLinkedDeque: "
+ cld);
// Check if Geeks is present using contains()
if (cld.contains("Geeks")) {
// Displaying message
System.out.println("Geeks is present");
}
else {
// Displaying message
System.out.println("Geeks not present");
}
}
}
輸出:
ConcurrentLinkedDeque: [Welcome, To, Geeks, 4, Geeks] Geeks is present
相關用法
- Java ConcurrentLinkedDeque pop()用法及代碼示例
- Java ConcurrentLinkedDeque offer()用法及代碼示例
- Java ConcurrentLinkedDeque remove()用法及代碼示例
- Java ConcurrentLinkedDeque addAll()用法及代碼示例
- Java ConcurrentLinkedDeque push()用法及代碼示例
- Java ConcurrentLinkedDeque isEmpty()用法及代碼示例
- Java ConcurrentLinkedDeque Spliterator()用法及代碼示例
- Java ConcurrentLinkedDeque用法及代碼示例
- Java ConcurrentLinkedDeque add()用法及代碼示例
- Java ConcurrentLinkedDeque addFirst()用法及代碼示例
- Java ConcurrentLinkedDeque peekLast()用法及代碼示例
- Java ConcurrentLinkedDeque equals()用法及代碼示例
- Java ConcurrentLinkedDeque clear()用法及代碼示例
- Java ConcurrentLinkedDeque peek()用法及代碼示例
- Java ConcurrentLinkedDeque addLast()用法及代碼示例
注:本文由純淨天空篩選整理自Aishwarya Jayashankar大神的英文原創作品 ConcurrentLinkedDeque contains() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。