这个 JAVAutil。同时发生的LinkedTransferQueue。删除() 方法是Java中的一个内置函数,用于删除队列中存在的元素。
null
语法:
LinkedTransferQueue.remove(Object o)
参数: 该函数只接受一个参数 o i、 e.要移除的对象。
返回值: 成功移除对象时,函数返回true boolean值,否则返回false。
下面的程序演示了LinkedTransferQueue。remove()方法:
项目1: 队列中存在要删除的元素。
// Java Program Demonstrate remove() // method of LinkedTransferQueue import java.util.concurrent.LinkedTransferQueue; class LinkedTransferQueueRemoveExample1 { public static void main(String[] args) { // Initializing the queue LinkedTransferQueue<Integer> queue = new LinkedTransferQueue<Integer>(); // Adding elements to this queue for ( int i = 1 ; i <= 5 ; i++) queue.add(i); // Printing the elements of the queue System.out.println( "The elements in the queue are:" ); for (Integer i : queue) System.out.print(i + " " ); // remove() method will remove the specified // element from the queue queue.remove( 1 ); queue.remove( 5 ); // Printing the elements of the queue System.out.println( "Remaining elements in queue : " ); for (Integer i : queue) System.out.print(i + " " ); } } |
输出:
The elements in the queue are: 1 2 3 4 5 Remaining elements in queue : 2 3 4
项目2: 队列中不存在要删除的元素。
// Java Program Demonstrate remove() // method of LinkedTransferQueue import java.util.concurrent.LinkedTransferQueue; class LinkedTransferQueueRemoveExample2 { 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); // Printing the elements of the queue System.out.println( "The elements in the queue are:" ); for (Integer i : queue) System.out.print(i + " " ); // remove() method will remove the specified // element from the queue queue.remove( 1 ); queue.remove( 5 ); // Printing the elements of the queue System.out.println( "Remaining elements in queue : " ); for (Integer i : queue) System.out.print(i + " " ); } } |
输出:
The elements in the queue are: 10 11 12 13 14 15 Remaining elements in queue : 10 11 12 13 14 15
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END