如果ConcurrentLinkedQueue包含作为参数传递的对象o,则ConcurrentLinkedQueue的contains()方法返回true。当且仅当此ConcurrentLinkedQueue包含至少一个等于作为参数传递的对象o的元素e,即o.equals(e)时,此方法才返回true。
用法:
public boolean contains(Object o)
参数:此方法采用代表对象的单个参数O来检查ConcurrentLinkedQueue是否包含指定的对象。
返回值:如果此ConcurrentLinkedQueue包含对象,则此方法返回true。
以下示例程序旨在说明ConcurrentLinkedQueue的contains()方法:
示例1:
// Java Program Demonstrate contains()
// method of ConcurrentLinkedQueue
import java.util.concurrent.*;
public class GFG {
public static void main(String[] args)
{
// create an ConcurrentLinkedQueue
ConcurrentLinkedQueue<String>
queue = new ConcurrentLinkedQueue<String>();
// Add String to queue
queue.add("Aman");
queue.add("Amar");
queue.add("Sanjeet");
queue.add("Rabi");
// Displaying the existing ConcurrentLinkedQueue
System.out.println("ConcurrentLinkedQueue: " + queue);
// check whether queue contains String "Aman"
boolean response1 = queue.contains("Aman");
// print after applying contains method
System.out.println("queue contains String \"Aman\" : "
+ response1);
// check whether queue contains "Ram"
boolean response2 = queue.contains("Ram");
// print after applying contains method
System.out.println("queue contains String \"Ram\" : "
+ response2);
}
}
输出:
ConcurrentLinkedQueue: [Aman, Amar, Sanjeet, Rabi] queue contains String "Aman" : true queue contains String "Ram" : false
示例2:
// Java Program Demonstrate contains()
// method of ConcurrentLinkedQueue
import java.util.concurrent.*;
public class GFG {
public static void main(String[] args)
{
// create an ConcurrentLinkedQueue
ConcurrentLinkedQueue<Integer>
queue = new ConcurrentLinkedQueue<Integer>();
// Add Numbers to queue
queue.add(4353);
queue.add(7824);
queue.add(78249);
queue.add(8724);
// Displaying the existing ConcurrentLinkedQueue
System.out.println("ConcurrentLinkedQueue: " + queue);
// check whether queue contains 78249
boolean response1 = queue.contains(78249);
// print after applying contains method
System.out.println("queue contains Number 78249 : "
+ response1);
// check whether queue contains 9876
boolean response2 = queue.contains(9876);
// print after applying contains method
System.out.println("queue contains Number 9876: "
+ response2);
}
}
输出:
ConcurrentLinkedQueue: [4353, 7824, 78249, 8724] queue contains Number 78249 : true queue contains Number 9876: false
相关用法
- Java ConcurrentLinkedQueue add()用法及代码示例
- Java ConcurrentLinkedQueue isEmpty()用法及代码示例
- Java ConcurrentLinkedQueue iterator()用法及代码示例
- Java ConcurrentLinkedQueue spliterator()用法及代码示例
- Java ConcurrentLinkedQueue offer()用法及代码示例
- Java ConcurrentLinkedQueue toArray()用法及代码示例
- Java ConcurrentLinkedQueue addAll()用法及代码示例
- Java ConcurrentLinkedQueue peek()用法及代码示例
- Java ConcurrentLinkedQueue remove()用法及代码示例
- Java ConcurrentLinkedQueue size()用法及代码示例
- Java ConcurrentLinkedQueue poll()用法及代码示例
- Java ConcurrentLinkedQueue用法及代码示例
- Java Java lang.Long.byteValue()用法及代码示例
- Java Java.util.Collections.rotate()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 ConcurrentLinkedQueue contains() method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。