这个 包含() 方法 ConcurrentLinkedQueue 如果ConcurrentLinkedQueue包含作为参数传递的对象o,则返回true。当且仅当此ConcurrentLinkedQueue包含至少一个元素e,该元素e等于作为参数传递的对象o,即o.equals(e),则此方法返回true。
null
语法:
public boolean contains(Object o)
参数: 此方法只接受一个参数 O 表示检查ConcurrentLinkedQueue是否包含指定对象的对象。
返回: 此方法返回 符合事实的 如果此ConcurrentLinkedQueue包含该对象。
下面的程序演示了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
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END