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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。