Java中的LinkedTransferQueue contains()方法

这个 包含() 方法 JAVAutil。同时发生的链接传输队列 是Java中的内置函数,如果此队列中存在指定元素,则返回true boolean值,否则返回false。

null

语法:

LinkedTransferQueue.contains(Object o)

参数: 该函数只接受一个参数 o i、 e.检查该队列中是否存在。

返回值: 该函数返回一个布尔值。如果此队列中存在指定的元素,则返回True,否则返回False。

下面的程序演示了LinkedTransferQueue。contains()方法:

项目1:

// Java Program Demonstrate contains()
// method of LinkedTransferQueue
import java.util.concurrent.*;
class LinkedTransferQueueContainsExample1 {
public static void main(String[] args)
{
// Initializing the queue
LinkedTransferQueue<Integer>
queue = new LinkedTransferQueue<Integer>();
// Adding elements to this queue
for ( int i = 10 ; i <= 15 ; i++)
queue.add(i);
// Checks if 9 is present in the queue
if (queue.contains( 9 ))
System.out.println( "9 is present in the queue." );
else
System.out.println( "9 is not present in the queue." );
}
}


输出:

9 is not present in the queue.

项目2:

// Java Program Demonstrate contains()
// method of LinkedTransferQueue */
import java.util.concurrent.*;
class LinkedTransferQueueContainsExample2 {
public static void main(String[] args)
{
// Initializing the queue
LinkedTransferQueue<String>
queue = new LinkedTransferQueue<String>();
// Adding elements to this queue
queue.add( "Gfg" );
queue.add( "is" );
queue.add( "fun" );
// Checks if Gfg is present in the queue
if (queue.contains( "Gfg" ))
System.out.println( "Gfg is present in the queue." );
else
System.out.println( "Gfg is not present in the queue." );
}
}


输出:

Gfg is present in the queue.

参考 : https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/LinkedTransferQueue.html#contains(java.lang.Object)

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享