LinkedBlockingDeque的contains(Object o)方法檢查容器中是否存在參數中傳遞的元素。如果該元素存在於容器中,則返回true,否則返回false值。
用法:
public boolean contains(Object o)
參數:此方法接受一個強製性參數o,該參數要檢查容器中是否存在容器。
返回值:如果該元素存在,則此方法返回true,否則返回false。
以下示例程序旨在說明LinkedBlockingDeque的contains()方法:
示例1:
// Java Program Demonstrate contains()
// method of LinkedBlockingDeque
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws IllegalStateException
{
// create object of LinkedBlockingDeque
LinkedBlockingDeque<Integer> LBD
= new LinkedBlockingDeque<Integer>();
// Add numbers to end of LinkedBlockingDeque
LBD.add(10);
LBD.add(20);
LBD.add(30);
LBD.add(40);
// before removing print queue
System.out.println("Linked Blocking Deque: " + LBD);
// check for presence using function
if (LBD.contains(10)) {
System.out.println("Linked Blocking Deque contains 10");
}
else {
System.out.println("Linked Blocking Deque does not contain 10");
}
}
}
輸出:
Linked Blocking Deque: [10, 20, 30, 40] Linked Blocking Deque contains 10
示例2:
// Java Program Demonstrate contains()
// method of LinkedBlockingDeque
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws IllegalStateException
{
// create object of LinkedBlockingDeque
LinkedBlockingDeque<String> LBD
= new LinkedBlockingDeque<String>();
// Add numbers to end of LinkedBlockingDeque
LBD.add("ab");
LBD.add("cd");
LBD.add("fg");
LBD.add("xz");
// before removing print queue
System.out.println("Linked Blocking Deque: " + LBD);
// check for presence using function
if (LBD.contains("go")) {
System.out.println("Linked Blocking Deque contains 'go'");
}
else {
System.out.println("Linked Blocking Deque does not contain 'go'");
}
}
}
輸出:
Linked Blocking Deque: [ab, cd, fg, xz] Linked Blocking Deque does not contain 'go'
相關用法
- Java LinkedBlockingDeque put()用法及代碼示例
- Java LinkedBlockingDeque take()用法及代碼示例
- Java LinkedBlockingDeque pop()用法及代碼示例
- Java LinkedBlockingDeque add()用法及代碼示例
- Java LinkedBlockingDeque peekFirst()用法及代碼示例
- Java LinkedBlockingDeque addFirst()用法及代碼示例
- Java LinkedBlockingDeque element()用法及代碼示例
- Java LinkedBlockingDeque putLast()用法及代碼示例
- Java LinkedBlockingDeque remainingCapacity()用法及代碼示例
- Java LinkedBlockingDeque removeLast()用法及代碼示例
- Java LinkedBlockingDeque putFirst()用法及代碼示例
- Java LinkedBlockingDeque removeFirst()用法及代碼示例
- Java LinkedBlockingDeque getFirst()用法及代碼示例
- Java LinkedBlockingDeque toString()用法及代碼示例
- Java LinkedBlockingDeque spliterator()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 LinkedBlockingDeque contains() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。